Cocos Creator in action system that thing

Action system that can be implemented within a certain period of time displacement, rotation, scaling, beating and other actions.

It should be noted that the action system with Cocos Creator compiler animation systems, motion systems programmer-oriented API interface, and animation system is designed by the compiler, they serve different usage scenarios, usually suitable action system Some simple displacement and rotation motion, and animation system is relatively strong in many, various properties can be added to the UI to do some complex animation.

A brief introduction to these friends, following entered

Action system API

// create a moving action, within 2 seconds to move to position x = 100, y = 100 in

 let action = cc.moveTo(2, 100, 100)

// perform actions, all actions require a target to implement it by runAction

node.runAction(action)

// effect

 

// we want to stop halfway when the motion of an object

node.stopAction(action)

// effect

 

// If there are multiple targets in the process of movement, want to stop all actions

node.stopAllActions()

These are the implements a simple action

If we want to achieve more motion effects can also be achieved through different interfaces.

Action system is also divided into intervals action and immediate action.

  Interval action : that is, to complete the specified action within a certain period of time.

cc.moveTo (2, 100, 100)     // moved to the target position, that is, whether we want to move the target in what position, the implementation of this action will in time move to within 2s x = 100, this position of y = 100. Parameter may be two to three parameters, if the two parameters, then there is no effect on the y-axis direction.

cc.moveBy(2, 100, 100)     // 移动指定的距离,也就是说,无论我们的想要移动的目标处于什么位置,执行这个动作后,都会在 2s 的时间内移动到距离上一个位置在 x 上增加 100 的距离,在 y 上增加 100 的距离,会产生叠加的效果。参数可以是2 ~ 3个参数,如果是两个参数,则表示在 y轴 的方向上没有效果。

// cc.moveBy(2, 100, 100) 的效果

 

cc.rotateTo(2, 1080 ,1080)     // 旋转到目标角度,在平面图上,参数为2 ~ 3个的效果是相同的,只有在三维效果才会不同。

 

cc.rotateBy(2, 1080, 1080)     // 在两秒内,旋转到指定的角度, 效果也是叠加的

cc.scaleTo(2, 0.5, 0.5)            // 在两秒内,将节点的大小缩放到指定的倍数

 

cc.scaleBy(2, 1.2, 1.2)     // 在两秒内,按指定的倍数去缩放节点,同样多次点击,效果会累加。

 

cc.skewTo(1, 60, 60)    // 在1 秒内,偏斜到目标角度

 

cc.skewBy(1, 40, 40)     // 在1秒内,偏斜指定的角度;多次点击,数值会累加

 

cc.jumpTo(3, 200, 200, 50, 5)       // 在3秒内,用跳动的方式移动到坐标为(200, 200)的位置,每次跳跃的高度为50,跳跃5次。

 

cc.jumpBy(2, 100, 100, 50, 5)          // 在2秒的时间内,用跳跃的方式指定的距离,(100, 100)会进行累加,每次跳跃的高度为50,跳跃次数为5次

 

cc.blink(3, 10)      // 在3秒内,闪烁10次,这个是基于透明度的闪烁

 

 

cc.fadeTo(3, 100)        // 在3秒内,修改透明度到100的值

 

cc.fadeIn(2)    // 渐显,参数为时间

cc.fadeOut(2)   // 渐隐,参数也为时间

cc.tintTo(3, 0, 255, 0)   // 在3秒内,修改颜色到指定值,后面的三个参数表示的是 rgb 的值

 

cc.tintBy(1, 100, 200, 100)  // 在1秒内按指定的增量(100, 200, 100)修改颜色,颜色会从 rgb(0, 0, 0) 开始增加

 

 

cc.delayTime(5)    // 表示延迟指定的时间量,用作延迟效果

cc.reverseTime()    // 用于反转目标动作的时间轴

  即时动作:立即发生的动作,没有时间的间隔

cc.show()      // 立即显示

cc.hide()        // 立即隐藏

cc.toggleVisibility()   // 显隐状态的切换

cc.removeSelf()    // 从父节点移除自身

cc.flipX()        // 沿X轴翻转

cc.flipY()        // 沿Y轴翻转

cc.place()       // 放置在目标位置,参数为X,Y的值

cc.callFunc()     // 执行一个回调函数

  缓动动作:目标在运动的时间内,会调节不同阶段的运动的速度

 

 

  容器动作

   通常我们在规划动作时,不会是一种单一的动作,而是多种动作结合运动达到我们想要的一种效果。

  cc.spawn    // 同步执行动作,也就是说,可以在相同的时间段内,执行不同的动作达到同步的效果。比如说,在进行位移的同时,可以实现旋转和缩放等动作。

 

     cc.sequence    // 顺序执行动作,即在不同的时间段执行不同的动作

 

 

   cc.repeat      // 重复执行动作,代入执行动作的参数后,要加一个重复的次数

例如:

cc.repeat(cc.sequence(cc.moveTo(1, 400, 200), cc.moveTo(1, -400, -200),cc.delayTime(0.5), cc.tintBy(2, 10, 50, 10), cc.jumpTo(3, 400, -100, 100, 20),cc.flipY(true)), 10)
重复10次执行的动作
 
  cc.repeatForever     // 永久重复动作
  cc.speed     //  修改动作速率
例如: 
cc.speed(cc.sequence(cc.moveTo(5, 400, 200), cc.moveTo(5, -400, -200)),  x1)
   x1 的数值越大,则动作的速率越快;数值为负值时,则不改变速率。

Guess you like

Origin www.cnblogs.com/zhen-prz/p/10955573.html