cocos2dx的 runAction,假设某个动作重复运行用cc.RepeatForever:create,
多个动作连接运行用cc.Sequence:create,多个动作同一时候运行用cc.Spawn:create.
反复运行某个动作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(某动作)--一个动作不断反复运行用
反复运行某个动作n次,用 cc.Repeat:create
local rep1 = cc.Repeat:create(seq, 10)
精巧n秒,用DelayTime,使用方法例如以下:
cc.DelayTime:create(1.4)
多个动作的runAction
一个运行完成后再连接还有一个,用cc.Sequence:create
local 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, ccp(300,450)) --移动到某位置 --复位 以便让动画反复 local action6 = cc.FadeIn:create(0.01)--渐入 local action7 = cc.MoveTo:create(0.01, ccp(300,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,action2),action3,cc.Spawn:create(action4,action5),cc.Spawn:create(action6,action7))))--cc.RepeatForever:create(某动作)反复运行某个动作 screen:addChild(sprite)
action中回调方法cc.CallFunc:create()
local function removeThis()
ret:getParent():removeChild(ret, true)
Helper.nextAction()
end
--After 1.5 second, self will be removed.
ret:runAction( cc.Sequence:create(cc.DelayTime:create(1.4),cc.CallFunc:create(removeThis)))
———————————
http://blog.sina.com.cn/s/blog_6e5195850101ioxq.html
时间: 2024-11-03 05:05:16