Saqib Ilyas Posted May 5 Share Posted May 5 Hi I'm developing a space shooter game using PIXI.js. I have a GameScene class that creates an instance of a Hero object and several Fighter objects through a Fighters class. Once I detect a collision between a Fighter and a Hero, I send an explode() message to the Hero and Figter objects. Then, I create start a new GameScene, which creates a new Hero object and a new Fighters object. It all works fine the first time. But, on the second collision, the Hero.sprite, and Hero.shipSprite references are null when the control reaches the explode() method. I have written console.log()s in the update() method as well and after the first collision, the Hero.sprite and Hero.shipSprite references point to valid objects up until the explosion takes place. I've made sure that no other part of code is setting these attributes to null. I'm attaching a snapshot of the browser developer console. I'm using PIXI.js 8.0.2 with webpack bundler. My code is at https://github.com/msaqib/spaceshooter. I'll appreciate any help troubleshooting this. Quote Link to comment Share on other sites More sharing options...
Saqib Ilyas Posted May 6 Author Share Posted May 6 This was a logical error on my part. I wasn't removing the Bodies from the Matter-js World (or Composite as they like to call it now). I have a class named Fighters. I create a host of Fighter objects in it, and I was only removing the body of the Fighter that collided with the Hero. The others lingered around. The hint was when sometimes a Fighter object would appear to be moving with a sort of friction, while others moved just fine. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.