1. 程式人生 > >cocos2d-x lua發牌動畫

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