Jump to content

Collision detection on geometry?


ForgeableSum
 Share

Recommended Posts

I'm trying to figure out the best way to do collision detection with geometry vs images. Right now I'm having to add a geometry as a child to the image (or use getBounds), then looping through  all images and checking for intersects with intersectsRectangle, but I can't help but think there must be a better way. Is there anyway to have physics-enabled geometry so I can use more efficient collision-detection methods? 

Link to comment
Share on other sites

Maybe create an empty sprite and add the geometry object to that as a child, then enable physics on the sprite.

var _container = game.add.sprite(0,0);var geom = game.add.graphics(game.width, game.height);geom.beginFill(backgroundColor, backgroundOpacity);geom.x = 0;geom.y = 0;geom.drawRect(0, 0, 100, 100);_container.width = 100;_container.height = 100;_container.addChild(geom);game.physics.enable(_container, Phaser.Physics.ARCADE);

I hope it helps!

Link to comment
Share on other sites

Phaser.image and Phaser.sprite are both wrappers and javascript objects, yes Sprites have more functions and properties but that doesn't make them more heavy-weight than Images. But don't take my word for it you can set up simple jsPerf tests and check it out yourself. 

 

From experience (not that much in game development) I think that most performance drops are caused by poor optimization and/or a false algorithm and can be usually be solved by following a different approach.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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