dankfer

How to change just one axis scale from a particle

Recommended Posts

I'm trying to create a dash fade effect behind the player when it's executing the dodge ability. I'm doing this with a particle emitter (dashEm). It's all good except from one thing the particle sprites on the trail aren't going in the player direction, they don't scale in X axis.

How it should be in both directions:

how_should_be.JPG.b554b6c4eab67a0ae5c60ffeb3dc49b1.JPG

The actual problem, when player goes to left:

how_it_is.JPG.0a3a145c28f6de1ed1deb55c05d05d0a.JPG

The Player scaleX changes whenever the player presses left or right key.

measures.last.dir = (pressedKeys.right)?1:-1
player.scale.setTo(measures.last.dir*2.5, 2.5)

The emitter min and max scale are set to 2.5 same as player.

dashEm = game.add.emitter(0, 0, 200);
dashEm.makeParticles('particleDash');
dashEm.minParticleScale = 2.4;
dashEm.maxParticleScale = 2.6;
dashEm.lifespan = 400;
dashEm.minRotation = 0;
dashEm.maxRotation = 0;
dashEm.minParticleSpeed.setTo(0, 0);
dashEm.maxParticleSpeed.setTo(0, 0);
dashEm.gravity = -1400; // fix global gravity

 

The update. If the dodge happens I update the emitter position, set the trail direction(particles speed), and release them.

dashEm.x = player.x;
dashEm.y = player.y;

dashEm.minParticleSpeed.setTo(-100*measures.last.dir, 0);
dashEm.maxParticleSpeed.setTo(-1000*measures.last.dir, 0);

dashEm.emitParticle();

 

What I've tried in update

I've tried to attach the emitter as a child of player. But when the player changes its direction (scaleX) emitter also change and trail suddenly change too (logical it's his child).

I've tried to change directly emitter scale. It works fine for right direction but when facing left the emitter and trail just disappear.

dashEm.scale = new Phaser.Point(1*measures.last.dir, 1)

I've tried to use setScale emitter method. But all it does is reduce the scale of the particles to 1. Not even put them in the right direction, no matter what values I enter.

sx = 2.5 *measures.last.dir
sy = 2.5
dashEm.setScale(sx, sx, sy, sy)

I've tried modifying every property in the emitter that has something to do with the word scale and nothing works.

I'cant use the default minParticleScale & maxParticleScale because this properties modify the both axis X & Y. I just need to change X axis, otherwise the trail would be upside down.

 

 

Last thing! Reading the docs I've found in minParticleScale  the sentence "If you need to control each axis see minParticleScaleX" but there's no such property nor function!.

 

Hope I posted it well. Thanks for the help guys!

 

 

Share this post


Link to post
Share on other sites
  • Try the latest Phaser CE (if not already). Emitter had a bug where it would ignore identical min/max values for scale.
  • Avoid setting dashEm.scale because that flips the whole "layer" of particles.
  • You may not need to attach the emitter as a child of the player. All you really need is to set (emitX, emitY) to the player's position at the time the emitter starts.
  • You can monitor the emitter with phaser-debug-emitter.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now