组件:两帧图片互相切换的动画。

 

 

实现如下效果:

cocos2d-lua3.7组件篇(二)-两帧图片互相跳动

 

 

 

 

1.缓存动画对象

2.加载两帧图片

 

local MenuScene = class("MenuScene", function()
    return display.newScene("MenuScene")
end)

function MenuScene:ctor()


            local animate = cc.Animation:create()
            animate:addSpriteFrameWithFile("dog.png")
            animate:addSpriteFrameWithFile("dog2.png")
                animate:setLoops(-1)
            animate: setDelayPerUnit(2.8 / 14.0)

    display.setAnimationCache("haha",animate)

    local btn = ccui.Button:create("button/aaa_N.png", "", "", 0)  
        :pos(display.cx, 100)  
        :addTo(self)  
        --按钮文字  
        btn:setTitleText("按钮")  
        --字体颜色  
        btn:setTitleColor(cc.c3b(255, 255, 255))  
        --按钮的回调函数  
        btn:addTouchEventListener(function(sender, eventType)  
        if (2== eventType)  then  
            
            

            local action = cc.Animate:create(display.getAnimationCache("haha"))

            local sprite1 = display.newSprite("dog2.png")  
                :center()  
                :addTo(self)  
                :runAction(action)  

        end  
    end)  

--getAnimationCache





end

function MenuScene:onEnter()
    print("enter")
end

function MenuScene:onExit()
end

return MenuScene

 

 

 

 

 

相关文章:

  • 2021-06-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
  • 2022-12-23
  • 2021-06-30
  • 2021-07-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-26
相关资源
相似解决方案