Jump to content

How to remove together the mesh and particles from scene?


Recommended Posts

  • 2 weeks later...

Yes, but after I first time removed the mesh and it is not visible. A particle system attached to the object. It turns out that the object is not departed from the stage and just became invisible?

I have a lot of animated bullets the players released if they are not removed this will not cause memory leaks?

Link to comment
Share on other sites

Ok. In this example, I put the function "explosion" in the IF that checks collision bullets and mesh. After hitting it removes the mesh.

But despite the fact that the mesh removed IF continues to operate if run shot.
I do not understand how, after removal of the mesh can trigger collision check ?
Link to comment
Share on other sites



thought I might jump in with my two cents:


Dispose is a very magical function. It does a LOT to the mesh and to its internal references (and is helping a lot with memory consumption). The one thing it doesn't do is actually deleting the JS object. This is the developer's job. One of the reasons for that is that you COULD use the mesh even after disposing it (thou it is not recommended). The other reason, which is the more prominent one - you can set the object undefined inside an internal function of the object itself. 

this = null

doesn't look quite right...

There are a few ways of doing that (I would personally rearrange the entire playground), one of them is on line 48. Notice I am (de)referencing box1, which is a scope variable. This is, of course, allowed. Then before checking if they intersect, you need to check if box1 exists.


One more thing, and this is the reason why I had to recreate the plyround from scratch - when registering an event listener, you have to take care of removing it as well. Otherwise, this function will be called many times. As many times as you press play. A simple function does that - the scene.onDispose can handle this wonderfully. Lines 58-60 in the demo.


Another little thing - scene.registerBeforeRender will regiser this function for ever. The function will continue running, making your game slower and slower each time. Make you you unregister the function you registered. You could use the Mesh.registerBeforeRender (those functions are disposed when the mesh is disposed), the catch is that the mesh must be visible in order for this functions to run.



Quite a lot, I hope it is all clear.

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.

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.


  • Recently Browsing   0 members

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