Jump to content

How to rotate the emitter ?


weratius
 Share

Recommended Posts

Hello, guys!

 

I have a ship and an emitter (in attachment)

 

I can rotate the ship via left and right arrows:

if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {                myShip.body.angularVelocity = -200;                iAmRotatingNow = true;                if (this.burnEngines) {                    emitter.rotation = myShip.body.angularVelocity;                }            } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {                myShip.body.angularVelocity = 200;                iAmRotatingNow = true;                if (this.burnEngines) {                    emitter.rotation = myShip.body.angularVelocity;                }            }

Here I tried to use emitter.rotation but it just disappears

//EMITTERstartEngines: function() {        emitter = game.add.emitter(game.world.centerX, game.world.centerY, 400);        emitter.makeParticles('beam1');        emitter.gravity = 200;        emitter.emitX = myShip.x - 25;        emitter.emitY = myShip.y;        emitter.setAlpha(1, 0, 2000);        emitter.setScale(0.5, 0, 0.5, 0, 2000);        emitter.start(false, 3000, 3);        this.burnEngines = true;    }

Thank you)

post-14308-0-47542200-1445428691.png

Link to comment
Share on other sites

  • I think you'll want to set the emitter.rotation to match the myShip.rotation, instead of myShip.angularVelocity.
  • Also, depending on how you've set it up, You may not be entering the if block of the burnEngines check correctly.. Instead of if (this.burnEngines), just use if (burnEngines) instead. 

Here's a fiddle: https://jsfiddle.net/chongdashu/y1fkzr7j/5/ (n.b., use WASD instead of arrow keys to move/rotate)

 

 

There are two implementations in there, depending on whether you want the ship to continue rotating after a single press (version 2) of whether you want it to only rotate when a key is pressed (version 1). 

Just read the comments for more information.

 

Hope it helps!

Link to comment
Share on other sites

 

  • I think you'll want to set the emitter.rotation to match the myShip.rotation, instead of myShip.angularVelocity.
  • Also, depending on how you've set it up, You may not be entering the if block of the burnEngines check correctly.. Instead of if (this.burnEngines), just use if (burnEngines) instead. 

Here's a fiddle: https://jsfiddle.net/chongdashu/y1fkzr7j/5/

 

 

There are two implementations in there, depending on whether you want the ship to continue rotating after a single press (version 2) of whether you want it to only rotate when a key is pressed (version 1). 

Just read the comments for more information.

 

Hope it helps!

 

Thank for your answer.

 

what about burnEngines it is in the object, so I can access it via "this"

 

My problem is that the emitter rotates around some fixed coordinates, however myShip is a sprite which can go forward, can turn to right and so on

 

In other words it will be awesome to fix the emitter to the ship

 

I tried something like this:

emitter = game.add.emitter(myShip.x, myShip.y, 400);

Thank you!

Link to comment
Share on other sites

I see, if you want the emitter to always be relative to the ship, you can just try:

myShip.addChild(emitter)

Then you do not even have to manually set the rotation in the update anymore.

 

Here's a fiddle: https://jsfiddle.net/chongdashu/Lg1bfwma/ (n.b., use WASD instead of arrow keys to move/rotate)

Thank you very much.

But after adding your code, emitter had disappeared 

 

I did everything the same you did

Link to comment
Share on other sites

I had to hack the crap out of this to get a result similar to what you're looking for.

 

In phaser.js's emitParticle function:

if (!particle.angle) // Added condition for particle's angle. ~Tilde        particle.angle = 0;

In player.js, before emission:

this.sparkEmitter.forEach(function(item) {  item.rotation = this.rotation;}, this);

Keep in mind, though, I only have to do this once, not every frame. Doing it every frame will probably suck for performance.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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