Tween 类型
模块: cc
Tween 提供了一个简单灵活的方法来创建 action。相对于 Cocos 传统的 cc.Action,cc.Tween 在创建动画上要灵活非常多:
- 支持以链式结构的方式创建一个动画序列。
- 支持对任意对象的任意属性进行缓动,不再局限于节点上的属性,而
cc.Action添加一个属性的支持时还需要添加一个新的 action 类型。 - 支持与
cc.Action混用。 - 支持设置 Easing 或者 progress 函数。
示例
cc.tween(node)
.to(1, {scale: 2, position: cc.v3(100, 100, 100)})
.call(() => { console.log('This is a callback'); })
.by(1, {scale: 3, position: cc.v3(200, 200, 200)}, {easing: 'sineOutIn'})
.start(cc.find('Canvas/cocos'));
索引
方法
constructorstopAll停止所有缓动stopAllByTag停止所有指定标签的缓动stopAllByTarget停止所有指定对象的缓动then插入一个 action 或者 tween 到队列中target设置 tween 的 targetstart运行当前 tweenstop停止当前 tweentag设置缓动的标签clone克隆当前 tweenunion将之前所有的 action 整合为一个 action。bezierTo按照贝塞尔路径设置目标的 position 属性。bezierBy按照贝塞尔路径设置目标的 position 属性。flipX翻转目标的 scaleX 属性flipY翻转目标的 scaleY 属性blink通过设置目标的 opacity 属性达到闪烁效果to添加一个对属性进行绝对值计算的 actionby添加一个对属性进行相对值计算的 actionset直接设置 target 的属性delay添加一个延时 actioncall添加一个回调 actionhide添加一个隐藏 actionshow添加一个显示 actionremoveSelf添加一个移除自己 actionsequence添加一个队列 actionparallel添加一个并行 actionrepeat添加一个重复 action,这个 action 会将前一个动作作为他的参数。repeatForever添加一个永久重复 action,这个 action 会将前一个动作作为他的参数。reverseTime添加一个倒置时间 action,这个 action 会将前一个动作作为他的参数。
Details
方法
constructor
| meta | description |
|---|---|
| 定义于 | cocos2d/actions/tween.js:184 |
参数列表
targetObject
stopAll
停止所有缓动
| meta | description |
|---|---|
| 定义于 | cocos2d/actions/tween.js:189 |
stopAllByTag
停止所有指定标签的缓动
| meta | description |
|---|---|
| 定义于 | cocos2d/actions/tween.js:198 |
参数列表
tagnumber
stopAllByTarget
停止所有指定对象的缓动
| meta | description |
|---|---|
| 定义于 | cocos2d/actions/tween.js:208 |
参数列表
targetObject
then
插入一个 action 或者 tween 到队列中
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:219 |
参数列表
target
设置 tween 的 target
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:240 |
参数列表
targetObject
start
运行当前 tween
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:255 |
stop
停止当前 tween
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:288 |
tag
设置缓动的标签
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:306 |
参数列表
tagnumber
clone
克隆当前 tween
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:320 |
参数列表
targetObject
union
将之前所有的 action 整合为一个 action。
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:335 |
bezierTo
按照贝塞尔路径设置目标的 position 属性。
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:365 |
参数列表
durationnumberc1cc.Vec2c2cc.Vec2tocc.Vec2
bezierBy
按照贝塞尔路径设置目标的 position 属性。
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:388 |
参数列表
durationnumberc1cc.Vec2c2cc.Vec2tocc.Vec2
flipX
翻转目标的 scaleX 属性
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:412 |
flipY
翻转目标的 scaleY 属性
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:423 |
blink
通过设置目标的 opacity 属性达到闪烁效果
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:434 |
参数列表
to
添加一个对属性进行绝对值计算的 action
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:479 |
参数列表
by
添加一个对属性进行相对值计算的 action
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:500 |
参数列表
set
直接设置 target 的属性
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:521 |
参数列表
propsObject
delay
添加一个延时 action
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:536 |
参数列表
durationNumber
call
添加一个回调 action
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:547 |
参数列表
hide
添加一个隐藏 action
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:559 |
show
添加一个显示 action
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:569 |
removeSelf
添加一个移除自己 action
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:579 |
sequence
添加一个队列 action
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:589 |
参数列表
parallel
添加一个并行 action
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:601 |
参数列表
repeat
添加一个重复 action,这个 action 会将前一个动作作为他的参数。
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:617 |
参数列表
repeatForever
添加一个永久重复 action,这个 action 会将前一个动作作为他的参数。
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:629 |
参数列表
reverseTime
添加一个倒置时间 action,这个 action 会将前一个动作作为他的参数。
| meta | description |
|---|---|
| 返回 | Tween |
| 定义于 | cocos2d/actions/tween.js:640 |