cocos_2d中经常用到的动作, 用lua来写

1 移动到指定位置:

  local move = CCMoveTo:create(time, ccp(posx, posy))

  参数time:移动到指定位置所用的时间

  参数:ccp(posx, posy) 移动到指定位置的坐标

  CCMoveBy 和 CCMoveTo用法相同,但是效果不同

  而且reverse()可以获取CCMoveBy 相反的移动方向

  local move1 = CCMoveBy:create(time, ccp(posx, posy)):reverse()

2 缩放动作

  local scale = CCScaleTo:create(time, scale)

  参数tiem:缩放到指定比例所用的时间

  参数scale:缩放的比例

  CCScaleBy:create(time, scale)同样为缩放动作,

  reverse可以获取CCScaleBy的相反缩放比例

3 旋转动作

  local rotate = CCRotateTo:create(time, rotate)

  参数time:旋转所用的时间

  参数rotate:旋转度数(0-360)

4 倾斜动作

  local skew = CCSkewTo:create(time, degree1, degree2)

  参数 time:倾斜所用的时间

  参数degree1:x轴的倾斜角度

  参数degree2:y轴的倾斜角度

5 跳跃动作:

  local jump = CCJumpTo:create(time, ccp(posx, posy), height, count)

  参数time:跳跃到指定位置所需要的时间

  参数ccp: 指定位置坐标

  参数height: 跳跃高度

  参数count: 跳跃次数

  CCJumpBy和CCJumpTo用法一样

  reverse可以获取CCJumpTo和CCJumpBy的相反方向

6 创建一个渐变出现的动作

  local fadin = CCFadeIn:create(time)

  参数time:渐渐出现所用的时间

7 创建一个渐变消失的动作

 local fadeout = CCFadeOut:create(time)

参数time:渐渐消失所用的事件

8 创建一个色彩变化的消失动作

 local tintTo = CCTintTo:create(time, red, green, blue)

 参数time:消失动作所用的时间

 参数red:红色分量

 参数green:绿色分量

 参数blue: 蓝色分量

9 创建一个色彩出现的变化动作

local tintby = CCTintBy:create(time, red, green, blue)

 参数time:出现所用的时间

 参数red:红色分量

 参数green:绿色分量

 参数blue:蓝色分量

10 创建一个闪烁动作

  local blink = CCBlink:create(time, count)

  参数time:闪烁时间

  参数count:闪烁次数

  容易出现的bug:当执行过快时可能会导致控件自动隐藏

11 创建延时动作

  local delay= CCDelayTime:create(time)

  参数time:延时时间

12 创建一个球面轨迹进行旋转的动作

  local orbit = CCOrbitCamera(time, radius, deltaRadius, angleZ, deltaAngleZ, angleX, deltaAngleX)

  参数time:动作所用的时间

  参数radius:起始半径

  参数deltaRadius:半径差

  参数angleZ:起始Z角

  参数deltaAngleZ:旋转Z角的差

  参数angleX:起始X角

  参数deltaAngleX:旋转X角的差

13 创建一条曲线轨迹的动作

  首先创建点的数组

  local pointArray = CCPointArray:create(20)

  向点的数组中添加控制点

  pointArray:addControlPoint(ccp(pos, posy))

  控制点可以添加无数个,根据希望的路径添加控制点

  曲线的轨迹动作:

  local cardinalslineto = CCCardinalSplineTo:create(time, pointArray, 0)

  参数time:动作所用时间

  参数pointArray:控制点数组

  参数0:路径最柔和

  CCCardinalSplineTo和CCCardinalSplineBy用法相同,但是效果不同(待研究)

14 创建一个样条插值轨迹

  同样先创建控制点数组pointArray

  local catmullromto = CCCatmullRomTo:create(time, pointArray)

  参数time:动作所用时间

  参数pointArray:控制点数组

  CCCatmullRomBy和CCCatmullRomTo的用法相同,效果不同,待研究

15 创建一个跟随动作

  local follow = CCFollow:create(sp, CCRectMake(x, y, long, height))

  参数sp:跟随目标

  参数CCRectMake跟随范围

16 让目标动作缓慢开始

  以移动到指定目标为例:

  local move = CCMoveTo:create(time, ccp(posx, posy))

  local easebounceIn = CCEaseBounceIncreate(move)

17 让目标动作具有反弹力

  local easebounceOut = CCEaseBounceOutcreate(move)

18 让目标动作赋予反弹力,开始和结束的时候都反弹

  local easebounceInOut = CCEaseBounceInOut:create(move)

19 让目标动作赋予回力,以起点为回力点, 像拉弓一样

  local easeBackIn = CCEaseBackIn:create(move)

20 让目标动作赋予回力,以终点为回力点,

  local easeBackout = CCEaseBackOut:create(move)

21 让目标动作缓慢开始

  local easeExponentialIn = CCEaseExponentialIn:create(move)

22 让目标动作缓慢终止

  local easeExponentialInOut = CCEaseExponentialOut:create(move)

22 让目标动作缓慢开始再缓慢终止

  local easeExponentialInOut = CCEaseExponentialInOut:create(move)

23 让目标动作设置速率

  local easeRateAction = CCEaseRateAction:create(move, 3)

  参数move: 动作对象

  参数3: 速率

24 动作由慢到快

  local easeSineIn = CCEaseSineIn:create(move)

25 动作由快到慢

  local easeSineOut = CCEaseSineOut:create(move)

26 动作有慢到快, 再快到慢

  local easeSineInOut = CCEaseSineInOut:create(move)

27 让目标动作加速

  local speed = CCSpeed:create(move, 100)

  参数move:移动对象

  参数100:速度倍数

28 并行动作,多个动作同时执行

  在lua中如果希望两个动作同时执行可以使用:local spawn = CCSpawn:createWithTwoActions(move, blink)

  参数move:移动

  参数blink: 闪烁

  如果有两个以上的动作,可以先建一个数组,把要同时执行的动作添加到数组中,再把该数组添加到CCSpawn中

  创建数组:local array = CCArray:create()

        array:addObject(move)

        array:addObject(blink)

 把数组添加到并行序列spawn中

 local spawn = CCSpawn:create(array)

29 串行动作,让多个动作按照前后顺序执行

  在lua中如果希望两个动作按照顺序执行可以使用:local sequence= CCSequence:createWithTwoActions(move, blink)

  参数move:移动

  参数blink: 闪烁

  如果有两个以上的动作,可以先建一个数组,把要要执行的动作添加到数组中,再把该数组添加到CCSequence中

  创建数组:local array = CCArray:create()

        array:addObject(move)

        array:addObject(blink)

 把数组添加到串行序列sequence中

 local sequence= CCSequence:create(array)

 可以对CCSequence使用reverse进行反方向运动,但是要保证,串行序列中的动作都能执行反方向操作

30 对目标进行重复性动作

  local move = CCMoveTo:create(time, ccp(posx, posy))

  local move1 = CCMoveTo:create(time1, ccp(pos1x, pos1y))

  local sequence = createWithTwoActions(move, move1)

  local repeat = CCRepeat:create(sequence, 3)

  参数sequence: 要重复执行的动作

  参数3: 重复次数3此

31 永久性重复运动

  local move = CCMoveTo:create(time, ccp(posx, posy))

  local move1 = CCMoveTo:create(time1, ccp(pos1x, pos1y))

 local sequence = createWithTwoActions(move, move1)

  local repeatForever = CCRepeatForever:create(sequence )

  参数CCActionInterval:sequence :要执行的动作

32 创建一个回调函数动作

  local callfunc = CCCallFunc:create(func)

  参数func:要创建为动作的函数

33 执行所创建的动作

  xxxx:runAction(action)

34 停止所有的操作

  xxxx:stopAllActions()   

35 停止单个动作

  xxx:stopAction(action)