ForgeableSum Posted April 28, 2015 Share Posted April 28, 2015 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 More sharing options...
MichaelD Posted April 28, 2015 Share Posted April 28, 2015 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 More sharing options...
ForgeableSum Posted April 29, 2015 Author Share Posted April 29, 2015 This doesn't seem like a practical solution because each of the images would need to be sprites as well (images can't be physics-enabled). Link to comment Share on other sites More sharing options...
MichaelD Posted April 29, 2015 Share Posted April 29, 2015 Why do you need images instead of sprites? Since you want to have CD on them. Link to comment Share on other sites More sharing options...
ForgeableSum Posted April 29, 2015 Author Share Posted April 29, 2015 It's a performance concern for me - images are far more lightweight, but I suppose there's no way around using sprites. Link to comment Share on other sites More sharing options...
MichaelD Posted April 29, 2015 Share Posted April 29, 2015 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 More sharing options...
Recommended Posts