Jump to content

Object Storage in Browser


pdiddles03
 Share

Recommended Posts

So for the past few months I have been working on a space shooter that will eventually be released in the play store using the crosswalk project.  I'm using crosswalk because I need access to the native audio on the device because mobile html5 audio is just not good.  But my question is refering to Javascript.  So I have a shoot button the user holds down as they play.  It creates a new object every time a person holds it down and it creates a new bullet.  When the bullet reaches 0px, or the top of the screen, i remove it from the stage. My question is, how do i delete this object all together instead of just removing it from stage?  When a user holds it down or taps on the shoot button, it inserts the object into an array so I can loop through and animate each one. 

Link to comment
Share on other sites

When it reaches 0px, set the value of the index for the bullet in the Array to "null" and run this:

while(YOURARRAY.indexOf(null) !== -1) {	YOURARRAY.splice(YOURARRAY.indexOf(null), 1);}

It will remove all instances of "null" from the Array. 

Link to comment
Share on other sites

You can call ".destroy()" on a sprite to completely clean it up, then null out any references you have to it (in variables, objects, arrays, etc.) so the GC will cleanup what is left.

 

However if you are going to creating and removing many objects you should look into "Object Pooling" to reduce the GC churn of creating and destroying many objects quickly.

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