Sign in to follow this  

Problem with Weapon

Recommended Posts

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(,, 'player');
    this.enemy = game.add.sprite(500, 200, 'enemyBody');


    this.enterKey =;
    this.enterKey.onDown.add(this.pressEnterKey, this);

pressEnterKey: function(){
makeShoot: function(){
    this.player.rotation =, this.enemy);

    this.bullet = game.add.weapon(1, 'bullet');
    this.bullet.trackSprite(this.player, 0, 0, true);;

game.state.add('GameState', 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?

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.