Hello. I am trying to use Weapon class, and I found some problem.
Here is my code:
var game = new Phaser.Game(640, 360, Phaser.AUTO);
var GameState = {
preload: function(){
game.load.image('player', 'assets/images/player.png');
game.load.image('enemyBody', 'assets/images/enemyBody.png');
game.load.image('bullet', 'assets/images/bullet.png');
},
create: function(){
this.player = game.add.sprite(game.world.centerX, game.world.centerY, 'player');
this.enemy = game.add.sprite(500, 200, 'enemyBody');
//this.makeShoot();
this.enterKey = this.game.input.keyboard.addKey(Phaser.Keyboard.ENTER);
this.enterKey.onDown.add(this.pressEnterKey, this);
},
pressEnterKey: function(){
this.makeShoot();
},
makeShoot: function(){
this.player.rotation = this.game.physics.arcade.angleBetween(this.player, this.enemy);
this.bullet = game.add.weapon(1, 'bullet');
this.bullet.trackSprite(this.player, 0, 0, true);
this.bullet.fire();
}
};
game.state.add('GameState', GameState);
game.state.start('GameState');
When code is executing, after the FIRST press Enter bullet appears at (0, 0), then bullets appear at player position.
If I remove comment from commented line it works perfect.
Where is my mistake?