ArmTwo Posted March 24, 2017 Share Posted March 24, 2017 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 More sharing options...
samme Posted March 25, 2017 Share Posted March 25, 2017 It's necessary if the bullet pool already exists, but it creates this problem if it doesn't. A workaround is this._bulletClass = MyBulletClass; this.createBullets(30, imgSprite); Link to comment Share on other sites More sharing options...
ArmTwo Posted March 25, 2017 Author Share Posted March 25, 2017 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 More sharing options...
Recommended Posts