Punchausen Posted October 1, 2016 Share Posted October 1, 2016 Hi folks, I've been having a blast with the way Phaser has simplified the work I've been needing to do, for instance how easy it is now to create a weapon object and fire away with bullets... however, in the game I'm making, I need to be able to dynamically affect the x & y axis of the bullets while they are mid-flight; however I've not seen any way I can get a handle on any of these create bullet objects in order to be able to do anything to them. My other option is to create custom weapon/bullet objects, but before I do that, am I missing a trick - is there a way to be able to meddle with individual bullet properties while they are in mid-flight? Many thanks for any help! Link to comment Share on other sites More sharing options...
lumoludo Posted October 1, 2016 Share Posted October 1, 2016 I haven't used the weapon code, but by looking at the docs it appears that a Weapon has a bullets parameter, which is a regular display group. So if you have the instance of the weapon still, you should be able to do something like this: (Keep in mind, this is just my assumption and not a guarantee. I also typed this in here manually, so there's always the possibility of typos.) for (var i = 0; i < myWeapon.bullets.length; i++) { // Print the current x and y position of the each bullet to the console var bullet = myWeapon.bullets.children[i]; if (bullet.alive) console.log("Position of bullet #" + i + ": " + bullet.x + ", " + bullet.y; else console.log("Bullet #" + i + " is dead."); } samme 1 Link to comment Share on other sites More sharing options...
Punchausen Posted October 2, 2016 Author Share Posted October 2, 2016 That works perfectly! Thanks for the help, good man Link to comment Share on other sites More sharing options...
samme Posted October 2, 2016 Share Posted October 2, 2016 You can also modify a bullet at launch-time with the onFire signal. lumoludo 1 Link to comment Share on other sites More sharing options...
Recommended Posts