Jump to content

Performance unusable with Class Object


saibotlive
 Share

Recommended Posts

Whenever I create an external js class object for my sprites or create states, the performance of my game becomes unusable on mobile but if I have all my code in one js file without the use of creating states or any class object, it works very well. I have no idea why it does this on just mobile (IOS and Android). Is there something I could be missing?

Link to comment
Share on other sites

The reason is probably related to cleaning up after yourself, not the fact that you're using external files.

How are you removing the sprites? Are you sure you're clearing up any references you have to objects once you change states? 

 

You're likely running out of memory, use the chrome dev tools profiler to check your heap allocations.

 

I am currently working on a game, and it runs fine on mobile with ~250 objects at once, dying and creating new ones such that after a minute it probably has spawned over 4000 objects.

I had an issue at first until I found out the correct way to remove a sprite:

// View is a Phaser.Sprite      if( this._view.input ) {        this._view.input.destroy();      }      this._view.kill();      if (this._view.group) {        this._view.group.remove(this._view);      } else if (this._view.parent) {        this._view.parent.removeChild(this._view);      }

I added the "this._view.input.destroy" part as an assurance, but I'm not sure if that bit is required. Anyway without that kill + remove bit that your memory usage will go up and up until the framerate on mobile is unplayable

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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