Help: Phaser and rotating emitter (Part II)
http://www.html5gamedevs.com/topic/18049-how-to-rotate-the-emitter/#entry101978
by chongdashu
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.4.4/phaser.js"></script>
JavaScript
var game = new Phaser.Game(640, 480, Phaser.AUTO, '', {
preload: preload,
create: create,
update: update,
render: render,
collectCoin: function () {
coin.kill();
},
});
function preload() {
game.load.crossOrigin = 'anonymous';
game.load.image('ship', 'http://i.imgur.com/CD5TrXo.png');
game.load.image('beam1', 'http://i.imgur.com/9e9tX9W.png');
}
var myShip;
var emitter;
var bunEngines = false;
var text;
var text2;
function create() {
game.physics.startSystem(Phaser.Physics.Arcade);
game.world.setBounds(-320, -240, 640, 480);
myShip = game.add.sprite(0, 0, "ship");
myShip.anchor.set(0.5, 0.5);
game.physics.arcade.enable(myShip);
text = game.add.text(0, 200, "", {
"fill": "white",
font: "bold 12pt Consolas",
});
text.anchor.set(0.5, 0.5)
text2 = game.add.text(0, 220, "", {
"fill": "white",
font: "bold 12pt Consolas",
});
text2.anchor.set(0.5, 0.5);
startEngines();
}
//EMITTER
function startEngines() {
emitter = game.add.emitter(game.world.centerX, game.world.centerY, 200);
// emitter.anchor.set(0.5, 0.5);
emitter.makeParticles('beam1');
emitter.gravity = 0;
emitter.x = myShip.x - 25; // Note: don't modify emitX, just x
emitter.y = myShip.y; // Note: don't modify emitY, just y
emitter.setAlpha(1, 0, 2000);
emitter.setScale(0.5, 0, 0.5, 0, 5000);
emitter.start(false, 3000, 3);
// Note:
// Some settings to make it clearer what the angle
// of the emitter is.
// Right now it will just shoot right.
emitter.setXSpeed(500);
emitter.setYSpeed(0);
// Note:
// Add the emitter to the ship
myShip.addChild(emitter);
this.burnEngines = true;
}
function update() {
myShip.body.velocity.x = 0;
myShip.body.velocity.y = 0;
// Note:
// Pressing UP or W moves the ship FORWARD in the direction
// it is facing.
// (not just upwards to the top of the...