重复执行某个动作cc.RepeatForever:create
local action = cc.FadeOut:create(3)--淡出 local action = cc.FadeIn:create(3) -- 渐入 local action = cc.RotateBy:create(3.0,360) -- 旋转 local action = cc.ScaleTo:create(3,0.1) -- 缩放 cc.RepeatForever:create(某动作)--一个动作不断重复执行用
多个动作的runAction
一个执行完毕后再连接另一个,用cc.Sequence:createlocal sprite2 = cc.Sprite:create(img/equipment/background_root.png) sprite2:setPosition(cc.p(visibleSize.width/2,visibleSize.height/4)) mlayer:addChild(sprite2,10) local action = cc.FadeOut:create(3)--淡出 local action2 = cc.FadeIn:create(3) -- 渐入 sprite2:runAction(cc.Sequence:create(action,action2,action))
多个动作同时变化,用cc.Spawn:create
sprite:runAction(cc.Spawn:create(cc.RotateBy:create(3.0,360),cc.ScaleTo:create(3,0.1)))
实例:
local screen = cc.Director:getInstance():getRunningScene() local action1 = cc.ScaleTo:create(0.5,1) --放大 参数:时间和缩放尺寸 local action2 = cc.MoveTo:create(0.5,ccp(300,330)) --移动到某位置 local action3 = cc.ScaleTo:create(0.2,0.6) --缩小 参数:时间和缩放尺寸 local action4 = cc.FadeOut:create(2)--淡出 local action5 = cc.MoveTo:create(2,450)) --移动到某位置 --复位 以便让动画重复 local action6 = cc.FadeIn:create(0.01)--渐入 local action7 = cc.MoveTo:create(0.01,300)) --移动到某位置 local sprite = cc.Sprite:create(fonts/number_green.png) sprite:setTextureRect(cc.rect(120,0,120,28) ) sprite:setPosition(300,300) sprite:setAnchorPoint(ccp(0.5,0)) sprite:setScale(0.6) -- sprite:runAction(action1)--runAction执行一个动作 -- sprite:runAction(cc.Spawn:create(action1,action2))--cc.Spawn:create同时执行多个动作 -- sprite:runAction(cc.Sequence:create(cc.Spawn:create(action1,action2),action3,cc.Spawn:create(action4,action5)))--cc.Sequence:create循序执行多个动作 sprite:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.Spawn:create(action1,action5),cc.Spawn:create(action6,action7))))--cc.RepeatForever:create(某动作)重复执行某个动作 screen:addChild(sprite)