0

我正在使用以下代码播放爆炸动画,当它完成循环计数时,如何删除动画?

        function showExplotion(event) 
            local sheetData = { width=32, height=32, numFrames=13, sheetContentWidth=128, sheetContentHeight=128 }
            local mySheet = graphics.newImageSheet( "media/fire.png", sheetData )
              local sequenceData = {
                --{ name = "normalRun", start=1, count=13, loopCount = 1, time=800 }
                { name = "fastRun", frames={ 1,2,4,5,6,7,8,9,10,11,12,13 }, time=800, loopCount = 1 }
            }

            local animation = display.newSprite( mySheet, sequenceData )
            animation.x = event.x
            animation.y = event.y
            animation:play()
        end
4

1 回答 1

2

您可以将侦听器添加到您的精灵动画以检测它的阶段

function showExplotion(event) 


        local sheetData = { width=32, height=32, numFrames=13, sheetContentWidth=128, sheetContentHeight=128 }
        local mySheet = graphics.newImageSheet( "media/fire.png", sheetData )
        local sequenceData = {
            --{ name = "normalRun", start=1, count=13, loopCount = 1, time=800 }
            { name = "fastRun", frames={ 1,2,4,5,6,7,8,9,10,11,12,13 }, time=800, loopCount = 1 }
        }

        local animation = display.newSprite( mySheet, sequenceData )
        animation.x = event.x
        animation.y = event.y
        animation:play()

       local function mySpriteListener( event )

         if ( event.phase == "ended" ) then
              animation:removeSelf()
              animation = nil
         end
      end

       animation:addEventListener( "sprite", mySpriteListener )  

  end
于 2013-07-02T00:49:02.840 回答