Alex10 Posted November 17, 2015 Share Posted November 17, 2015 When I double-click remove mesh and start the particle at 1 second. And I assume that after the particles are removed together with the mesh from the scene. But if I again double click will do it again the particles appear again.How to remove together the mesh and particles? Example: http://www.babylonjs-playground.com/#7JOOL Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 17, 2015 Share Posted November 17, 2015 Hello, if you double click then you go to explosion and so you create a new particleSystem If you want to remove particleSystem, just use system.dispose() Quote Link to comment Share on other sites More sharing options...
Alex10 Posted November 27, 2015 Author Share Posted November 27, 2015 I added to the end of the function: setTimeout( function(){ particleSystem.dispose(); }, 3000 );http://www.babylonjs-playground.com/#7JOOL#1but after the disappearance of the object the particle system is still in place when the dblclick event appears. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 27, 2015 Share Posted November 27, 2015 This is what I mentioned: Hello, if you double click then you go to explosion and so you create a new particleSystem Quote Link to comment Share on other sites More sharing options...
Alex10 Posted November 27, 2015 Author Share Posted November 27, 2015 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? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 28, 2015 Share Posted November 28, 2015 Could you please illustrate your issues on the playground? It will be far easier for me to understand the problem Quote Link to comment Share on other sites More sharing options...
Alex10 Posted November 29, 2015 Author Share Posted November 29, 2015 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 ? http://www.babylonjs-playground.com/#VWXHP#12 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 30, 2015 Share Posted November 30, 2015 This is because you disposed it but you are still referencing it in your code:if (bullet.intersectsMesh(box1, true)) { Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 30, 2015 Share Posted November 30, 2015 howdy! thought I might jump in with my two cents:http://www.babylonjs-playground.com/#1NSBMU#1Dispose 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 = nulldoesn'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. So!Quite a lot, I hope it is all clear. The Leftover and Temechon 2 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.