lua对多个精灵执行一系列动作,延时失效
function MainPlayerCards:sendCards() local winSize = cc.Director:getInstance():getWinSize() local nSize = #self.handCard for i =1,nSize do if self.handCard[i] then self.handCard[i]:removeFromParent(true) self.handCard[i] = nil end end local function sendOneCard(pNode) local tag = pNode:getTag() pNode:removeFromParent(true) local sp = cc.Sprite:createWithSpriteFrameName(string.format("l_%d.png",self.handCard[tag])) sp:setPosition(cc.p(self:CardPos(tag))) table.insert(self.handCard, sp) self:addChild(sp) end for i=1,nSize do local pBackSp = cc.Sprite:createWithSpriteFrameName("l_back.png") pBackSp:setPosition(cc.p(winSize.width/2,winSize.height/2)) pBackSp:setTag(i) self:addChild(pBackSp,nSize -i) local arrayAction ={} table.insert(arrayAction, cc.DelayTime:create((i)*0.2)) table.insert(arrayAction, cc.MoveTo:create(0.2, cc.p(self:CardPos(i)))) table.insert(arrayAction, cc.CallFunc:create(sendOneCard)) pBackSp:runAction(cc.Sequence:create(arrayAction)) end end
上述为:从中间开始,一张一张进行发牌动画的创建
如果table.insert(arrayAction, cc.DelayTime:create((i)*0.2))中,将时间改为常量,并没有按想像的执行完延时后,在进行下一次for循环,而是所有牌的动画一次性执行完毕,并且很多时候,我们看不到,误以为moveto动作没执行,另外哪位有关于table.insert(arrayAction, cc.CallFunc:create(sendOneCard))中cc.CallFunc中函数传参的资料,希望赐教!