Jump to content

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


    this.enterKey = this.game.input.keyboard.addKey(Phaser.Keyboard.ENTER);
    this.enterKey.onDown.add(this.pressEnterKey, this);

pressEnterKey: function(){
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);

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?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...