Jump to content

Is there any way to get a handle on the bullet objects mid-flight?


Punchausen
 Share

Recommended Posts

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

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.");
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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