coco2dx 的动画有XXTo和XXBy两类,分别是移动和递增2种方式,而且可以实现多个动作同时叠加进行(开启CC_ENABLE_STACKABLE_ACTIONS宏时,默认是开启的)。
By 算的是相对于节点对象的当前位置,To 算的是绝对位置,不考虑当前节点对象在哪。如果你想动作的表现是相对于 Node 当前位置的,就用 By,相对的想让动作的表现是按照坐标的绝对位置就用 To。
dotween也有该功能的实现,DOBlendableMoveBy
DOBlendableMoveBy(Vector3 by, float duration, bool snapping)
Tweens a Transform’s position BY the given value (as if it was set to relative), in a way that allows other DOBlendableMove tweens to work together on the same target, instead than fight each other as multiple DOMove would do.
snapping If TRUE the tween will smoothly snap all values to integers.
// Tween a target by moving it by 3,3,0
// while blending another move by -3,0,0 that will loop 3 times
// (using the default OutQuad ease)
transform.DOBlendableMoveBy(new Vector3(3, 3, 0), 3);
transform.DOBlendableMoveBy(new Vector3(-3, 0, 0), 1f).SetLoops(3, LoopType.Yoyo);
其他还有:
DOBlendableLocalMoveBy(Vector3 by, float duration, bool snapping)
DOBlendableRotateBy(Vector3 by, float duration, RotateMode mode)
DOBlendableLocalRotateBy(Vector3 by, float duration, RotateMode mode)
DOBlendableScaleBy(Vector3 by, float duration)
DOBlendableColor(Color to, float duration)
还有个SetRelative
接口,这个接口只是改了目标值的计算方式,并不能叠加:
If isRelative is TRUE sets the tween as relative (the endValue will be calculated as startValue + endValue instead of being used directly). In case of Sequences, sets all the nested tweens as relative.
IMPORTANT: Has no effect on From tweens, since in that case you directly choose if the tween is relative or not when chaining the From setting.
Has no effect if the tween has already started.
transform.DOMoveX(4, 1).SetRelative();