Jump to content

Ninja physics - using the 34 "shape types"


Recommended Posts

So from looking at the Ninja Physics Lab code and the png files, am I correct in saying that to use the Ninja Physics tiles for collisions, the easiest approach is to take the existing "ninja-tiles32.png" file (or the larger px version as needed, or your own px scale) and then modify the individual sprite images as required for your game's particular look, with the important point being to keep the shape types in their specific spritesheet position.


ie sprite frame 0 = an empty collision square, sprite frame 1 = a full square collision tile, frames 6 + 7 make up the lower halves of a convex circle, etc etc....


From looking at the code in http://docs.phaser.io/Tile.js.html at the bottom, I can see the hardcoded numbers, so these numbers should correspond with the spritesheet frame numbers back in your spritesheet....

Phaser.Physics.Ninja.Tile.EMPTY = 0;Phaser.Physics.Ninja.Tile.FULL = 1;//fullAABB tilePhaser.Physics.Ninja.Tile.SLOPE_45DEGpn = 2;//45-degree triangle, whose normal is (+ve,-ve)Phaser.Physics.Ninja.Tile.SLOPE_45DEGnn = 3;//(+ve,+ve)Phaser.Physics.Ninja.Tile.SLOPE_45DEGnp = 4;//(-ve,+ve)Phaser.Physics.Ninja.Tile.SLOPE_45DEGpp = 5;//(-ve,-ve)Phaser.Physics.Ninja.Tile.CONCAVEpn = 6;//1/4-circle cutoutPhaser.Physics.Ninja.Tile.CONCAVEnn = 7;Phaser.Physics.Ninja.Tile.CONCAVEnp = 8;Phaser.Physics.Ninja.Tile.CONCAVEpp = 9;Phaser.Physics.Ninja.Tile.CONVEXpn = 10;//1/4/circlePhaser.Physics.Ninja.Tile.CONVEXnn = 11;Phaser.Physics.Ninja.Tile.CONVEXnp = 12;Phaser.Physics.Ninja.Tile.CONVEXpp = 13;Phaser.Physics.Ninja.Tile.SLOPE_22DEGpnS = 14;//22.5 degree slopePhaser.Physics.Ninja.Tile.SLOPE_22DEGnnS = 15;Phaser.Physics.Ninja.Tile.SLOPE_22DEGnpS = 16;Phaser.Physics.Ninja.Tile.SLOPE_22DEGppS = 17;Phaser.Physics.Ninja.Tile.SLOPE_22DEGpnB = 18;Phaser.Physics.Ninja.Tile.SLOPE_22DEGnnB = 19;Phaser.Physics.Ninja.Tile.SLOPE_22DEGnpB = 20;Phaser.Physics.Ninja.Tile.SLOPE_22DEGppB = 21;Phaser.Physics.Ninja.Tile.SLOPE_67DEGpnS = 22;//67.5 degree slopePhaser.Physics.Ninja.Tile.SLOPE_67DEGnnS = 23;Phaser.Physics.Ninja.Tile.SLOPE_67DEGnpS = 24;Phaser.Physics.Ninja.Tile.SLOPE_67DEGppS = 25;Phaser.Physics.Ninja.Tile.SLOPE_67DEGpnB = 26;Phaser.Physics.Ninja.Tile.SLOPE_67DEGnnB = 27;Phaser.Physics.Ninja.Tile.SLOPE_67DEGnpB = 28;Phaser.Physics.Ninja.Tile.SLOPE_67DEGppB = 29;Phaser.Physics.Ninja.Tile.HALFd = 30;//half-full tilesPhaser.Physics.Ninja.Tile.HALFr = 31;Phaser.Physics.Ninja.Tile.HALFu = 32;Phaser.Physics.Ninja.Tile.HALFl = 33;Phaser.Physics.Ninja.Tile.TYPE_EMPTY = 0;Phaser.Physics.Ninja.Tile.TYPE_FULL = 1;Phaser.Physics.Ninja.Tile.TYPE_45DEG = 2;Phaser.Physics.Ninja.Tile.TYPE_CONCAVE = 6;Phaser.Physics.Ninja.Tile.TYPE_CONVEX = 10;Phaser.Physics.Ninja.Tile.TYPE_22DEGs = 14;Phaser.Physics.Ninja.Tile.TYPE_22DEGb = 18;Phaser.Physics.Ninja.Tile.TYPE_67DEGs = 22;Phaser.Physics.Ninja.Tile.TYPE_67DEGb = 26;Phaser.Physics.Ninja.Tile.TYPE_HALF = 30;

....and in the Lab code, I can see it doing a "game.physics.ninja.enableTile(tile, tile.frame);" where tile.frame is the reference to the spritesheet frame (which was sorted out nicely for us by Tiled in the exported JSON file which was then loaded into the Phaser game).


32 px Ninja spritesheet for reference:





Executive Summary, if you want to use Tiled and Ninja, keep the shape types in their respective spritesheet positions per the Lab example, then when you want to load in your JSON file and initialise the physics system, you can just use the simple code pattern defined in the Lab.... hmmm, which I guess in hindsight is a long winded way to say "hack the example!"

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...