Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
phaser-tiled-hull
Advanced tools
A module for Phaser for reducing neighboring tiles into a single shape (a hull)
A module for use with Phaser for reducing neighboring tiles in a tilemap into a single shape - a polygon "hull". For example, the demo tilemap (left) is converted into a series of hulls (right, each hull is visualized in a random color). The hulls contain information about the edges - including midpoints, normals and line lengths. See src/example/js/states/start.js for example usage.
This was built to find hulls for casting dynamic shadows in a 2D lighting engine, but the hull calculation might be useful for simplifying things like collision detection.
(Note: if you are viewing this on GitHub or NPM, you might want to check out the HTML documentation here.)
Whether you include the library as a script tag or import it as a module, Phaser is a dependency. The library expects Phaser to be in the global scope.
Download the dist/phaser-tiled-hull.min.js here and include it in your HTML:
<script src="dist/phaser-tiled-hull.min.js"></script>
Inside of your own script, you can now use the global phaserTiledHull
:
phaserTiledHull(...)
See src/example/js/states/start.js for example usage in global mode.
Install the dependency:
npm install --save phaser-tiled-hull
To use the babelified and minified library:
import phaserTiledHull from "phaser-tiled-hull";
phaserTiledHull(...)
To use the raw es6 library (so you can transpile it to match your own project settings):
import phaserTiledHull from "phaser-tiled-hull/src/library";
phaserTiledHull(...)
Setup:
// Assuming:
// - You've imported phaserTiledHull via one of the methods above.
// - You've created a Phaser game, loaded a tilemap called "map-1" and loaded a
// tileset called "tiles"
// Add the cached tilemap
const tilemap = game.add.tilemap("map-1");
// Add the tileset - 1st param is name in Tiled, 2nd param is of image in Phaser's cache
const wallTileset = tilemap.addTilesetImage("tiles", "tiles");
// Load your layers (via layer name from Tiled)
tilemap.createLayer("bg", g.width, g.height);
const wallLayer = tilemap.createLayer("walls", g.width, g.height);
// Set all tiles in the wall layer to be colliding
tilemap.setCollisionBetween(wallTileset.firstgid, wallTileset.firstgid +
wallTileset.total, true, wallLayer);
Examples:
// Method 1: find hull from colliding tiles
const hulls = phaserTiledHull(wallLayer, {checkCollide: true});
// -> hulls is now an array where each hull is represented as an array of PolygonEdges
// Method 2: find hull only using only the first 5 tiles in the tileset
const hulls = phaserTiledHull(wallLayer, {tileIndices: [1, 2, 3, 4, 5]});
// Method 3: find hull using a tile property that was set up in Tiled. To set properties:
// open Tiled, go to the tilesets panel and click the edit tileset button.)
const hulls = phaserTiledHull(wallLayer, {tileProperty: "checkHull"});
// Mixed method: you can combine options. When combining options, a tile only has to pass
// ONE of the checks in order to end up included in one of the hulls.
const hulls = phaserTiledHull(wallLayer, {
tileIndices: [1],
tileProperty: "checkHull"
});
Tilemap: Hull:
X X X X X X
X ⟶ X X
X X X X X X
See the scripts section of package.json. Main commands:
npm run build:all ⟶ Builds & minifies the library & example
npm run dev ⟶ Builds the library & example and serves it via browser-sync
Directory structure:
├── src/
├── example/ ES6 example of how to use the library
└── phaser-tiled-hull/ ES6 source for the library
├── public/ The babel transpiled example code
└── dist/ The transpiled library and source maps
├── phaser-tiled-hull.js Transpiled
└── phaser-tiled-hull.minjs Transpiled and minified
@mikewesthad, @retwedt
FAQs
A module for Phaser for reducing neighboring tiles into a single shape (a hull)
The npm package phaser-tiled-hull receives a total of 0 weekly downloads. As such, phaser-tiled-hull popularity was classified as not popular.
We found that phaser-tiled-hull demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.