cocos2dx的 runAction,若是某個動做反覆執行用cc.RepeatForever:create, 多個動做鏈接執行用cc.Sequence:create,多個動做同時執行用cc.Spawn:create.
重複執行某個動做cc.RepeatForever:createhtml
?動畫
1
2
3
4
5
6
|
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(某動做)--一個動做不斷重複執行用
|
多個動做的runActionui
一個執行完畢後再鏈接另外一個,用cc.Sequence:createspa
?code
1
2
3
4
5
6
7
|
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:createorm
?htm
1
|
sprite:runAction(cc.Spawn:create(cc.RotateBy:create(
3.0
,
360
),cc.ScaleTo:create(
3
,
0.1
)))
|
------------------------------------- 實例示範:
ip
?ci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
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)
|