Jump to content

Error in bulletClass of the Phaser.Weapon


ArmTwo
 Share

Recommended Posts

Hi,

In the documentation of the Weapon, the property bulletClass speak the follow:

bulletClass : Object => "The Class of the bullets that are launched by this Weapon. Defaults Phaser.Bullet, but can be overridden before calling createBullets and set to your own class type."

that could be written:

class MyWeapon extens Phaser.Weapon {
  contructor(){
    super();
    
    this.bulletClass = MyBulletClass; /*error here*/
    this.createBullets(30, imgSprite);
  }
}

the problem is that que the method bulletClass executes internally the code:

https://github.com/photonstorm/phaser/blob/v2.6.2/src/plugins/weapon/WeaponPlugin.js#L1130

this.bullets.classType = this._bulletClass;

But this.bullets still not was instantiate(null), so throws the error "can not read property 'classType' of undefined".

If i comments the line, everything works.

Would this line really necessary?

I'm using Phaser 2.6.2.

Link to comment
Share on other sites

Hi @samme, the problem is that the typescript accuses error, saying that the property not exists. But works anyway.

could have a conditional for check if this.bullets is null. i looked the Phaser CE and it have this:

//prevent crash if weapon's bullets have not yet been initialized
if (this.bullets) {
    this.bullets.classType = this._bulletClass;
}

 

Link to comment
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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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