【问题标题】:Remove animation at the end of the loop count在循环计数结束时删除动画
【发布时间】:2013-07-01 21:35:49
【问题描述】:

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

        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

【问题讨论】:

    标签: loops animation sdk lua coronasdk


    【解决方案1】:

    你可以在你的精灵动画中添加监听器来检测它的相位

    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
    

    【讨论】:

    • 谢谢。 *动画 = nil not ==nil
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 2015-10-08
    • 1970-01-01
    相关资源
    最近更新 更多