cocos2d-x lua发牌动画

这里写图片描述
代码如下:

  --layout
    local laytest = ccui.Layout:create()
    laytest:setContentSize(cc.size(300,300))
    laytest:setPosition(cc.p(200, 300))
    laytest:setAnchorPoint(cc.p(0, 0))
layer:addChild(laytest)
-- callback
    local function menuItemHelpCallback1(sender)
       local HAND_CARD_COUNT=13
       for i=1,13 do
         local card = cardlist[i]
          card:stopAllActions()
          card:setVisible(true)
          card:setPosition(laytest:getContentSize().width/2, laytest:getContentSize().height)
          card:setRotation(0)
          card:runAction(transition.sequence({
            cc.DelayTime:create(i * 0.),
            cc.MoveTo:create(0.5,cc.p(45+18*(i-1),laytest:getContentSize().height/2)),
            }))
          end
    end

可以根据上面代码修改为很多种动画,例如:
这里写图片描述
代码

  --layout
    local laytest = ccui.Layout:create()
    laytest:setContentSize(cc.size(300,300))
    laytest:setPosition(cc.p(200, 300))
    laytest:setAnchorPoint(cc.p(0, 0))
layer:addChild(laytest)
-- callback
    local function menuItemHelpCallback1(sender)
       local HAND_CARD_COUNT=13
       for i=1,13 do
         local card = cardlist[i]
          card:stopAllActions()
          card:setVisible(true)
          card:setPosition(laytest:getContentSize().width/2, laytest:getContentSize().height)
          card:setRotation(0)
          card:runAction(transition.sequence({
            cc.DelayTime:create(i * 0.),
            cc.MoveTo:create(0.5,cc.p(45+18*(i-1),laytest:getContentSize().height/2)),
            }))
          end
    end

这里写图片描述

local function setcardimg(card,img)
        --local t = cc.TextureCache:getInstance():addImage(img)
        local t=cc.Director:getInstance():getTextureCache():addImage(img)
        card:setTexture(t)    
    end
 local function menuItemHelpCallback1(sender)
       local HAND_CARD_COUNT=13
       for i=1,13 do
         local card = cardlist[i]
          setcardimg(card,"card_b.png")
          card:stopAllActions()
          card:setVisible(true)
          card:setPosition(laytest:getContentSize().width/2, laytest:getContentSize().height)
          card:setRotation(0)
          local xy = cc.p(45+30*(i-1),laytest:getContentSize().height/2)
          card:runAction(transition.sequence({
            cc.DelayTime:create(i * 0.05),
            cc.MoveTo:create(0.2,xy),
            cc.CallFunc:create(function()
                setcardimg(card,"card4.png")
            end),
            }))
          end

    end

猜你喜欢

转载自blog.csdn.net/mofiu/article/details/78751138