pdiddles03 Posted May 11, 2015 Share Posted May 11, 2015 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. Quote Link to comment Share on other sites More sharing options...
Oyed Posted May 11, 2015 Share Posted May 11, 2015 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. Quote Link to comment Share on other sites More sharing options...
xerver Posted May 13, 2015 Share Posted May 13, 2015 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. Quote Link to comment Share on other sites More sharing options...
pdiddles03 Posted May 14, 2015 Author Share Posted May 14, 2015 Perfect. Exactly what I need. Thanks! Quote Link to comment Share on other sites More sharing options...
pdiddles03 Posted May 15, 2015 Author Share Posted May 15, 2015 I do have one more question though. How can i found out how many objects i have stored in the gpu to make sure it is working? Quote Link to comment Share on other sites More sharing options...
xerver Posted May 16, 2015 Share Posted May 16, 2015 http://benvanik.github.io/WebGL-Inspector/ 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.