Jump to content

Sprite attribute gets set to null apparently on its own


Saqib Ilyas
 Share

Recommended Posts

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.

Screenshot 2024-05-05 at 6.07.28 PM.png

Link to comment
Share on other sites

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.

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