动画的性能问题

当我在模拟器上运行模拟器时,一切都很顺利,但一旦我在实际设备上运行我的游戏时,在加载/开始动画时游戏会冻结一会儿。

我不知道我做错了什么。 这是加载动画的代码:

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
        -- 从5个烟雾动画中选择
         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)) -- 随机旋转动画
    animation[index]:play()

    -- 清除函数
    local function mySpriteListener( event )
        if ( event.phase == "ended" ) then

            -- 清除不可见的火药桶
            if invisibleTnt ~= nil and animation[index] ~= nil then
                   ...
            end

            -- 清除火焰
            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
    -- 运行清除函数
    animation[index]:addEventListener( "sprite", mySpriteListener )
end
点赞
用户1870706
用户1870706

如果你将要一遍又一遍地使用这些图片,那么我会提前加载它们,然后只在需要时生成雪碧图。这将节省加载图片和解析图片的时间。

2013-08-04 23:12:06