Jump to content

Animated particle position issues


GaryS
 Share

Recommended Posts

I'm having issues trying to get my head around animated particles.

I have a texture atlast representing an explosion animation. I can use this standalone with no problems, however when I try to use it with a particle emitter I'm having difficulty with positioning. It also seems that the animation is half sized and I can't tell why.

Here's my code:

    //  Player explosion
    this.playerExplode = function(x, y) {
        this.emitter     = this.add.emitter(x, y, 4);
        this.emitter.makeParticles('explosion');
        this.emitter.forEach(function(singleParticle) {
            singleParticle.animations.add('explosion', Phaser.Animation.generateFrameNames("explosion_",  1, 11, ".png", 2));
            singleParticle.animations.play('explosion', 15, false, true);
        });
        this.emitter.start(true, 2000, null, 10);
    } 

The function is called on a player collision with an obstacle. I pass the X,Y co-ordinates to the function and create the emitter as you can see.

If I dump out the emitter object to the console, I can see the X,Y co-ordinates are correct.

I've picked up the method for adding animations from some tutorial or other - I can't remember where but I've been all over the web looking for a simple animated particle example and can't seem to find one. This is where I've landed - if there are any better or more standard ways to add an animation to a particle, please let me know!

If I dump out the position of each 'singleParticle', they all come back as 0.

Oddly enough, I can see the animation (zoomed out by 50%, it would seem!) in the top right corner of the screen. I'm not sure why this is.

Can anyone help out here?

 

Thanks

Link to comment
Share on other sites

Seems I've gotten to the bottom of this, but I'm a little surprised.

For ease of debugging, I've been using toFixed() on my positions to output integers. Seems that doing so in this context causes issues... If I pass the X,Y co-ordinates as is, it all seems to work as I'd expect.

 

Ho hum.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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