ghclark2 Posted November 14, 2017 Share Posted November 14, 2017 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 More sharing options...
samme Posted November 14, 2017 Share Posted November 14, 2017 add(this.weapon.fire, this.weapon) should be the right context, but probably that's passing the signal's arguments into fire, where they don't match. So try it just as add(function () { this.weapon.fire(); }, this) ghclark2 1 Link to comment Share on other sites More sharing options...
ghclark2 Posted November 14, 2017 Author Share Posted November 14, 2017 That's great - many thanks! Link to comment Share on other sites More sharing options...
Recommended Posts