mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
@@ -2,6 +2,12 @@
|
||||
* @category tween
|
||||
*/
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Built-in string value definition for the cache function.
|
||||
* @zh
|
||||
* 内置缓动函数的字符串值定义。
|
||||
*/
|
||||
export type TweenEasing =
|
||||
'linear' | 'smooth' | 'fade' |
|
||||
'quadIn' | 'quadOut' | 'quadInOut' | 'quadOutIn' |
|
||||
@@ -15,10 +21,52 @@ export type TweenEasing =
|
||||
'backIn' | 'backOut' | 'backInOut' | 'backOutIn' |
|
||||
'bounceIn' | 'bounceOut' | 'bounceInOut' | 'bounceOutIn' ;
|
||||
|
||||
|
||||
/**
|
||||
* @en
|
||||
* The interface of optional property.
|
||||
* @zh
|
||||
* 缓动的可选属性的接口定义。
|
||||
*/
|
||||
export interface ITweenOption {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Easing function, you can pass in a string or custom function.
|
||||
* @zh
|
||||
* 缓动函数,可以使用已有的,也可以传入自定义的函数。
|
||||
*/
|
||||
easing?: TweenEasing | ((k: number) => number);
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Interpolation functin, you can pass in a custom function.
|
||||
* @zh
|
||||
* 插值函数,参数的意义 start:起始值,end:目标值,current:当前值,ratio:当前进度
|
||||
*/
|
||||
progress?: (start: number, end: number, current: number, ratio: number) => number;
|
||||
|
||||
/**
|
||||
* @en
|
||||
* A callback that is triggered when a tween action is started.
|
||||
* @zh
|
||||
* 回调,当缓动动作启动时触发。
|
||||
*/
|
||||
onStart?: (target?: object) => void;
|
||||
|
||||
/**
|
||||
* @en
|
||||
* A callback that is triggered when a tween action is update.
|
||||
* @zh
|
||||
* 回调,当缓动动作更新时触发。
|
||||
*/
|
||||
onUpdate?: (target?: object, ratio?: number) => void;
|
||||
|
||||
/**
|
||||
* @en
|
||||
* A callback that is triggered when a tween action is completed.
|
||||
* @zh
|
||||
* 回调,当缓动动作完成时触发。
|
||||
*/
|
||||
onComplete?: (target?: object) => void;
|
||||
}
|
||||
@@ -6,17 +6,49 @@ import { System, Director, director } from "../core";
|
||||
import { ActionManager } from "./actions/action-manager";
|
||||
import { EDITOR } from 'internal:constants';
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Tween system.
|
||||
* @zh
|
||||
* 缓动系统。
|
||||
*/
|
||||
export class TweenSystem extends System {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* The ID flag of the system.
|
||||
* @zh
|
||||
* 此系统的 ID 标记。
|
||||
*/
|
||||
static readonly ID = 'tween';
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Gets the instance of the tween system.
|
||||
* @zh
|
||||
* 获取缓动系统的实例。
|
||||
*/
|
||||
static readonly instance: TweenSystem;
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Gets the action manager.
|
||||
* @zh
|
||||
* 获取动作管理器。
|
||||
*/
|
||||
get ActionManager () {
|
||||
return this.actionMgr;
|
||||
}
|
||||
|
||||
private readonly actionMgr = new ActionManager();
|
||||
|
||||
/**
|
||||
* @en
|
||||
* The postUpdate will auto execute after all compnents update and lateUpdate.
|
||||
* @zh
|
||||
* 此方法会在组件 lateUpdate 之后自动执行。
|
||||
* @param dt 间隔时间
|
||||
*/
|
||||
postUpdate (dt: number) {
|
||||
if (!EDITOR || this._executeInEditMode) {
|
||||
this.actionMgr.update(dt);
|
||||
|
||||
+26
-26
@@ -40,9 +40,9 @@ export class Tween {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Insert an action or tween to this sequence
|
||||
* Insert an action or tween to this sequence.
|
||||
* @zh
|
||||
* 插入一个 tween 到队列中
|
||||
* 插入一个 tween 到队列中。
|
||||
* @method then
|
||||
* @param {Tween} other
|
||||
* @return {Tween}
|
||||
@@ -59,9 +59,9 @@ export class Tween {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Set tween target
|
||||
* Sets tween target.
|
||||
* @zh
|
||||
* 设置 tween 的 target
|
||||
* 设置 tween 的 target。
|
||||
* @method target
|
||||
* @param {Object} target
|
||||
* @return {Tween}
|
||||
@@ -81,9 +81,9 @@ export class Tween {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Start this tween
|
||||
* Start this tween.
|
||||
* @zh
|
||||
* 运行当前 tween
|
||||
* 运行当前 tween。
|
||||
* @method start
|
||||
* @return {Tween}
|
||||
*/
|
||||
@@ -102,9 +102,9 @@ export class Tween {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Stop this tween
|
||||
* Stop this tween.
|
||||
* @zh
|
||||
* 停止当前 tween
|
||||
* 停止当前 tween。
|
||||
* @method stop
|
||||
* @return {Tween}
|
||||
*/
|
||||
@@ -117,9 +117,9 @@ export class Tween {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Clone a tween
|
||||
* Clone a tween.
|
||||
* @zh
|
||||
* 克隆当前 tween
|
||||
* 克隆当前 tween。
|
||||
* @method clone
|
||||
* @param {Object} [target]
|
||||
* @return {Tween}
|
||||
@@ -146,9 +146,9 @@ export class Tween {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Add an action which calculate with absolute value
|
||||
* Add an action which calculate with absolute value.
|
||||
* @zh
|
||||
* 添加一个对属性进行绝对值计算的 action
|
||||
* 添加一个对属性进行绝对值计算的 action。
|
||||
* @method to
|
||||
* @param {number} duration 缓动时间,单位为秒
|
||||
* @param {Object} props 缓动的属性列表
|
||||
@@ -167,9 +167,9 @@ export class Tween {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Add an action which calculate with relative value
|
||||
* Add an action which calculate with relative value.
|
||||
* @zh
|
||||
* 添加一个对属性进行相对值计算的 action
|
||||
* 添加一个对属性进行相对值计算的 action。
|
||||
* @method by
|
||||
* @param {number} duration 缓动时间,单位为秒
|
||||
* @param {Object} props 缓动的属性列表
|
||||
@@ -188,9 +188,9 @@ export class Tween {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Directly set target properties
|
||||
* Directly set target properties.
|
||||
* @zh
|
||||
* 直接设置 target 的属性
|
||||
* 直接设置 target 的属性。
|
||||
* @method set
|
||||
* @param {Object} props
|
||||
* @return {Tween}
|
||||
@@ -203,9 +203,9 @@ export class Tween {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Add an delay action
|
||||
* Add an delay action.
|
||||
* @zh
|
||||
* 添加一个延时 action
|
||||
* 添加一个延时 action。
|
||||
* @method delay
|
||||
* @param {number} duration
|
||||
* @return {Tween}
|
||||
@@ -218,9 +218,9 @@ export class Tween {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Add an callback action
|
||||
* Add an callback action.
|
||||
* @zh
|
||||
* 添加一个回调 action
|
||||
* 添加一个回调 action。
|
||||
* @method call
|
||||
* @param {Function} callback
|
||||
* @return {Tween}
|
||||
@@ -233,9 +233,9 @@ export class Tween {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Add an sequence action
|
||||
* Add an sequence action.
|
||||
* @zh
|
||||
* 添加一个队列 action
|
||||
* 添加一个队列 action。
|
||||
* @method sequence
|
||||
* @param {Tween} action
|
||||
* @param {Tween} ...actions
|
||||
@@ -249,9 +249,9 @@ export class Tween {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Add an parallel action
|
||||
* Add an parallel action.
|
||||
* @zh
|
||||
* 添加一个并行 action
|
||||
* 添加一个并行 action。
|
||||
* @method parallel
|
||||
* @param {Tween} action
|
||||
* @param {Tween} ...actions
|
||||
@@ -265,7 +265,7 @@ export class Tween {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Add an repeat action.
|
||||
* Add an repeat action.
|
||||
* This action will integrate before actions to a sequence action as their parameters.
|
||||
* @zh
|
||||
* 添加一个重复 action,这个 action 会将前一个动作作为他的参数。
|
||||
@@ -295,7 +295,7 @@ export class Tween {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Add an repeat forever action
|
||||
* Add an repeat forever action.
|
||||
* This action will integrate before actions to a sequence action as their parameters.
|
||||
* @zh
|
||||
* 添加一个永久重复 action,这个 action 会将前一个动作作为他的参数。
|
||||
|
||||
@@ -72,14 +72,14 @@
|
||||
"default": true
|
||||
},
|
||||
{
|
||||
"text": "tween.js Adapter",
|
||||
"description": "Integrate tween.js in Creator 3D.",
|
||||
"text": "Tween",
|
||||
"description": "Tween support.",
|
||||
"entry": "tween",
|
||||
"default": true
|
||||
},
|
||||
{
|
||||
"text": "Terrain",
|
||||
"description": "Integrate tween.js in Creator 3D.",
|
||||
"description": "Terrain support",
|
||||
"entry": "terrain",
|
||||
"default": true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user