Jump to content

what context to pass for weapon.fire function


ghclark2
 Share

Recommended Posts

Hi,

I am really confused why I am getting errors with this code from the weapon plugin:
 

  create: function() {
    //load current level
    this.loadLevel();

    this.weapon = this.game.add.weapon(-1, 'explode');
    this.weapon.fireFrom.setTo(300,300, 1, 1);

    this.weapon.bulletKillType = Phaser.Weapon.KILL_CAMERA_BOUNDS;
    this.weapon.bulletGravity.y = -1000;

    this.input.keyboard.addKey(Phaser.KeyCode.SPACEBAR)
        .onDown.add(this.weapon.fire, this);

The error is:

phaser.js:100951 Uncaught TypeError: Cannot read property 'width' of undefined
    at Object.Phaser.Weapon.fire (phaser.js:100951)

It seems to be an issue with the context, but I have tried this.weapon, this.state, this.game all to no avail. Annoyingly if I run ZPlat.GameState.weapon.fire() from the console it shoots fine.

If anyone can see what I'm doing wrong I'd be very grateful.

Thanks, Gordon

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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