Jump to content

Collision shapes


jjimenez
 Share

Recommended Posts

Hi,

 

the latest weeks I have been working on a little game. This is my first game using Phaser, so at the begining I started using the arcade physic system. But, with the arcade physic, it's just possible to handle sprite collisions by boxes. As far as I know, to create a sprite with other kind of collision shape, you need to use another physic system, like ninja.

 

I was looking some info in the internet, and seeing some examples in the phaser official page. The only way I found to do that, was to use ninja physic, and create a tile with it in this way:

game.physics.ninja.enableTile(sprite, TILE_SHAPE);

Reading the code in the examples, I understood that, the possible tile shapes are those in this picture: http://examples.phaser.io/assets/physics/ninja-tiles128.png

 

My problem was that my sprite didn't fit any shape in the picture. So finally, what I did was to create a group with two sprites, each of the sprites has it's own tile with a different shape (in my case, these shapes were 21 and 22). And then, apply the movement and all required properties to the group or to all the sprites in the case i needed it.

 

My question is, is this the right way of doing this? Or is there any better way (cleaner, efficient, etc.) of doing this?

 

Thanks in advance!

Link to comment
Share on other sites

i would use p2 physics ..  that way you have no limit at all.. you can design your shapes in an editor like tiled (on an object layer with "polylines") in whatever form you like them..  be careful to close your polylines precisely (use snap to grid or hold down control)

 

here is an example on how to do it :)

 

http://www.html5gamedevs.com/topic/6556-how-to-export-from-tiled-and-integrate-into-phaser/?p=39495

Link to comment
Share on other sites

if you need custom shapes for sprites use p2 physics and physics editor

https://www.codeandweb.com/physicseditor

 

create your polygons, export as json  and import them into your game

 game.load.image('bullet', './assets/bullet.png'); game.load.physics('physicsData', './assets/polygons/bullet.json');
 bullet = game.add.sprite(250, game.world.height - 250, 'bullet'); game.physics.p2.enable(bullet); bullet.body.clearShapes(); bullet.body.loadPolygon('physicsData','bullet');
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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