BdR Posted August 14, 2014 Share Posted August 14, 2014 I'm working on a game where the player controls a rotating vehicle which can collide with enemies and coins. I'm aware that the sprite body (aka "hit area") can only be a rectangle and it cannot be rotated. So instead, I've created 3 separate invisible sprites that only serve as hit detection areas. These hit areas rotate around the player's axis as the player rotates and this all works fine. See image and github code below, it's just test code where the plane follows the mouse cursor and you can rotate it with the cursor keys:https://github.com/BdR76/phasercollision My question is this:I'm wondering if there is a more efficient way to do this. Is there a way to access the sprites in a group like playerHitGroup.sprites[0] and playerHitGroup.sprites[1] etc.? That way I could just create the sprites in a for-loop and I wouldn't have to keep 3 separate vars for the sprites like the code is now:var dum1;var dum2;var dum3;// setup the player hit spritesdum1 = game.add.sprite(0, 0, null, 0, playerHitGroup);dum1.body.setSize(32, 32);dum1.anchor.setTo(0.5, 0.5);dum2 = game.add.sprite(0, 0, null, 0, playerHitGroup);dum2.body.setSize(32, 32);dum2.anchor.setTo(0.5, 0.5);dum3 = game.add.sprite(0, 0, null, 0, playerHitGroup);dum3.body.setSize(32, 32);dum3.anchor.setTo(0.5, 0.5); Link to comment Share on other sites More sharing options...
Dumtard Posted August 14, 2014 Share Posted August 14, 2014 http://docs.phaser.io/Phaser.Group.html#getAt or you can access the children through playerHitGroup.children[0] and playerHitGroup.children[1] etc. Link to comment Share on other sites More sharing options...
Recommended Posts