Ase Posted June 1, 2018 Share Posted June 1, 2018 Hello! Until now I refrained myself to come here for help while working on my game. But here I am, at lost face to something I don't know how to fix. I'm doing a game with a lot of moving sprites that I create from tiled objects with create from object. When the player dies, I kill and destroy all the blocks with this. //Kill blocks goin out LevelBox.prototype.killBlokCheck = function (tile) { if (tile.body.y >= this.world.height || tile.body.y <= 0) { //this is how I tried to correct the problem, thinking badly destroyed animations were the cause of it tile.animations.destroy(); //this always worked well and executes quite fast even on 300+ sprites at a time tile.destroy(); tile.kill(); } } Problem is, in my last level I began putting some animations on those many sprites. //HEAVY FREEZE // if (this.tilemap=="level_3") // { // // this.movables_1.callAll('animations.add', 'animations', 'idle', [0,1,2,3,4,5,6,7,8], 20, true); // this.movables_1.callAll('animations.play', 'animations', 'idle', "20", "true"); // // this.movables_2.callAll('animations.add', 'animations', 'idle', [0,1,2,3,4,5,6,7,8], 20, true); // this.movables_2.callAll('animations.play', 'animations', 'idle', "20", "true"); // // this.movables_3.callAll('animations.add', 'animations', 'idle', [0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,35,37], 10, true); // this.movables_3.callAll('animations.play', 'animations', 'idle', "10", "true"); // // this.movables_4.callAll('animations.add', 'animations', 'idle', [0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,35], 30, true); // this.movables_4.callAll('animations.play', 'animations', 'idle', "30", "true"); // // } And when I respawn my blocks I do the exact same thing. Problem is : When the player dies, it causes a short freeze when everything resets. This is quite acceptable. But next reset is longer, next one, ever longer, soon it takes 10 secondes to do and for a die and retry it is excrutiating... Do you have any idea from where could this come. I long to understand this. I Thank you for your help! =D Link to comment Share on other sites More sharing options...
samme Posted June 1, 2018 Share Posted June 1, 2018 27 minutes ago, Ase said: But next reset is longer, next one, ever longer, soon it takes 10 secondes to do and for a die and retry it is excrutiating... https://developers.google.com/web/tools/chrome-devtools/rendering-tools/js-execution Link to comment Share on other sites More sharing options...
Ase Posted June 1, 2018 Author Share Posted June 1, 2018 Hi samme, thx for showing me this. I'm not quite sure if I get the right infos out of it, but it seems "requestAnimationFrame.forceSetTimeOut._onLoop" is what's taking most time, but I don't know if this tool can help me find the reason why it is taking more and more time. in my CallAll where I add the animations, something called the _registerListener (the index of the animations listeners I suppose) takes quite some time too. Still unsure about which part is causing the aggravation. Sorry, I'm not well versed in those kind of situations =x Link to comment Share on other sites More sharing options...
casey Posted June 1, 2018 Share Posted June 1, 2018 How are you doing the reset exactly? Link to comment Share on other sites More sharing options...
Ase Posted June 2, 2018 Author Share Posted June 2, 2018 Well I call for each members of my sprite groups the function I put on top of the topic. Then for each group I call : //Re-create blocks LevelBox.prototype.resetBlockGroup = function (group, gID, sprite) { group.enableBody = true; this.map.createFromObjects('falling', gID, sprite, 0, true, false, group); group.setAll('body.immovable', true); } To recreate all sprites from object layer of my tilemap Finally I run the second bit of code I put in my first message. And that's when all goes awry. I know I should probably make a pool and put in it all my sprites with original position, then, better than destroying/recreating them simply put them back into place. But my code being what it is right now, I wanted to understand what was really going wrong here. Isn't the use of destroy THEN kill a bit redundant and problematic? I had some strange behaviors without le both of them at some time, trying to kill the sprite and its body. As of those animations I'm having a hard time understanding why it's harder to compute every time. Link to comment Share on other sites More sharing options...
samme Posted June 2, 2018 Share Posted June 2, 2018 tile.destroy() should be enough. You don't need animations.destroy() or kill(), but since you're not getting errors from those, I doubt they're causing problems. Link to comment Share on other sites More sharing options...
Recommended Posts