Jump to content

Strange freezes caused by adding a lot of animations


Recommended Posts


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
//this always worked well and executes quite fast even on 300+ sprites at a time


Problem is, in my last level I began putting some animations on those many sprites.

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

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

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

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