Performance problems with animation

When I run the simulator everything works smoothly, but once i run my game on the actual device, the game freezes for a moment when animation is being loaded/starts.

I don’t know what I did wrong.

here is the code that loads the animation:

    function showAnimation(event, type, index)                   if type == "explosion" then              sheetData = { width=100, height=100, numFrames=33, sheetContentWidth=1100, sheetContentHeight=300 }              mySheet = graphics.newImageSheet( "media/animations/Explosion.png", sheetData )              sequenceData = {                 { name = "fastRun", frames={ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33 }, time=1050, loopCount = 1 }             }         elseif type == "smoke" then             -- choose from 5 smokes animations              sheetData = { width=100, height=100, numFrames=23, sheetContentWidth=500, sheetContentHeight=500 }              mySheet = graphics.newImageSheet( "media/animations/smoke-" .. math.random(1,5)  .. ".png", sheetData )                           sequenceData = {                 { name = "fastRun", frames={ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 }, time=math.random(555, 1110), loopCount = 1 }             }             elseif type == "fire" then              sheetData = { width=40, height=40, numFrames=89, sheetContentWidth=400, sheetContentHeight=360 }              mySheet = graphics.newImageSheet( "media/animations/fire.png", sheetData )                           sequenceData = {                 { name = "fastRun", frames={ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89 }, time=6000, loopCount = 1 }             }             end              animation[index] = display.newSprite( mySheet, sequenceData )         animation[index].name = type         animation[index].id = index         animation[index].x = event.x         animation[index].y = event.y         animation[index]:rotate(math.random(-360, 360)) -- randomly rotate animation         animation[index]:play()                  -- clean up function          local function mySpriteListener( event )             if ( event.phase == "ended" ) then                              -- clean up invisibleTnt                  if invisibleTnt ~= nil and animation[index] ~= nil then                        ...                 end                                  -- clean up fire flames                 if flames ~= nil and animation[index] ~= nil then                    ...                 end                                  if animation[index] ~= nil then                     --animation[index]:removeSelf()                     animation[index]:getParent():remove( image )                     animation[index] = nil                 end             end         end         -- run clean up function         animation[index]:addEventListener( "sprite", mySpriteListener )      end  

This can be normal when you create the sprite images when the game is already running. Maybe you just need to preload the images, turn them invisible and work with this ones in the running game.

you are right. didn’t thought small animations needs to be preloaded.

Great to know I could help you with the info. I’m sitting here all the evening and fighting performance issues myself but this will take a while… so it’s good see your stuff running before going off to bed :wink:

This can be normal when you create the sprite images when the game is already running. Maybe you just need to preload the images, turn them invisible and work with this ones in the running game.

you are right. didn’t thought small animations needs to be preloaded.

Great to know I could help you with the info. I’m sitting here all the evening and fighting performance issues myself but this will take a while… so it’s good see your stuff running before going off to bed :wink: