Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add timeScale and pause()/resume() to cc.Tween #16098

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

finscn
Copy link
Contributor

@finscn finscn commented Aug 24, 2023

  • 新增 tween.timeScale 属性, 用来调节tween的速率
  • 新增 tween.pause()/resume() 方法, 用来暂停和恢复tween
  • 优化部分代码, 使其更简洁精准 ( 例如: 移除 _firstTick, 修改 sequence() 参数类型)
  • 优化格式, 符合tslint 要求.

transate by google :

  • Add tween.timeScale property, used to adjust the rate of tween
  • Add tween.pause()/resume() method, used to pause and resume tween
  • Optimize part of the code to make it more concise and precise (for example: remove _firstTick, modify sequence() parameter type)
  • Optimized format, in line with tslint requirements.

.

1. 为 action-interval 新增 timeScale 和 paused 属性, 用来实现 暂停 和 加减速.
2.   根据实际情况, function sequence 只需要接受数组参数.
3. 同时修正一些违背 tslint 规范的地方.
1.  新增 timeScale 属性, 来改变tween的速率.
2. 新增 pause / resume 方法, 用来暂停和恢复某个 tween
@finscn
Copy link
Contributor Author

finscn commented Aug 24, 2023

我英文不好 而且不了解 3.x 的代码注释规范, 所以注释部分如果写的不对 请帮忙修正. 谢谢

@finscn
Copy link
Contributor Author

finscn commented Aug 24, 2023

ESLint 没有通过 的部分 几乎都是原有代码, 我写的部分都是合规的.

@github-actions
Copy link

github-actions bot commented Aug 24, 2023

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -54026,8 +54026,17 @@
      *   .by(1, {scale: new Vec3(-1, -1, -1), position: new Vec3(-5, -5, -5)}, {easing: 'sineOutIn'})
      *   .start()
      */
     export class Tween<T> {
+        /**
+         * !#en set/get time scale for tween
+         * !#zh 设置/读取 tween 的 time scale (时间缩放参数)
+         * @property timeScale
+         * @type {Number}
+         * @default 1
+         */
+        get timeScale(): number;
+        set timeScale(value: number);
         constructor(target?: T | null);
         /**
          * @en Sets tween tag
          * @zh 设置缓动的标签
@@ -54067,8 +54076,28 @@
          * 停止当前 tween。
          */
         stop(): Tween<T>;
         /**
+         * !#en
+         * Pause this tween
+         * !#zh
+         * 暂停当前 tween
+         * @method pause
+         * @return {Tween}
+         * @typescript pause(): Tween<T>
+         */
+        pause(): Tween<T>;
+        /**
+         * !#en
+         * Resume this tween
+         * !#zh
+         * 从暂停状态恢复当前 tween
+         * @method resume
+         * @return {Tween}
+         * @typescript resume(): Tween<T>
+         */
+        resume(): Tween<T>;
+        /**
          * @en
          * Clone a tween.
          * @zh
          * 克隆当前 tween。
@@ -54237,9 +54266,9 @@
          * 停止所有指定对象的缓动
          */
         static stopAllByTarget(target?: object): void;
     }
-    export class TweenAction extends __private._cocos_tween_actions_action_interval__ActionInterval {
+    export class TweenAction extends codec {
         constructor(duration: number, props: any, opts?: ITweenOption);
         clone(): TweenAction;
         startWithTarget(target: Record<string, unknown>): void;
         update(t: number): void;
@@ -68636,147 +68665,8 @@
         };
         export type _cocos_tween_tween__OmitType<Base, Type> = _cocos_tween_tween__KeyPartial<Base, _cocos_tween_tween__AllowedNames<Base, Type>>;
         export type _cocos_tween_tween__ConstructorType<T> = _cocos_tween_tween__OmitType<T, Function>;
         /**
-         * @en
-         * Base class actions that do have a finite time duration. <br/>
-         * Possible actions: <br/>
-         * - An action with a duration of 0 seconds. <br/>
-         * - An action with a duration of 35.5 seconds.
-         *
-         * Infinite time actions are valid
-         * @zh 有限时间动作,这种动作拥有时长 duration 属性。
-         * @class FiniteTimeAction
-         * @extends Action
-         */
-        export class _cocos_tween_actions_action__FiniteTimeAction extends _cocos_tween_actions_action__Action {
-            _duration: number;
-            _timesForRepeat: number;
-            /**
-             * @en get duration of the action. (seconds).
-             * @zh 获取动作以秒为单位的持续时间。
-             * @method getDuration
-             * @return {Number}
-             */
-            getDuration(): number;
-            /**
-             * @en set duration of the action. (seconds).
-             * @zh 设置动作以秒为单位的持续时间。
-             * @method setDuration
-             * @param {Number} duration
-             */
-            setDuration(duration: number): void;
-            /**
-             * @en
-             * to copy object with deep copy.
-             * returns a clone of action.
-             * @zh 返回一个克隆的动作。
-             * @method clone
-             * @return {FiniteTimeAction}
-             */
-            clone(): _cocos_tween_actions_action__FiniteTimeAction;
-        }
-        /**
-         * @en
-         * <p> An interval action is an action that takes place within a certain period of time. <br/>
-         * It has an start time, and a finish time. The finish time is the parameter<br/>
-         * duration plus the start time.</p>
-         *
-         * <p>These CCActionInterval actions have some interesting properties, like:<br/>
-         * - They can run normally (default)  <br/>
-         * - They can run reversed with the reverse method   <br/>
-         * - They can run with the time altered with the Accelerate, AccelDeccel and Speed actions. </p>
-         *
-         * <p>For example, you can simulate a Ping Pong effect running the action normally and<br/>
-         * then running it again in Reverse mode. </p>
-         * @zh 时间间隔动作,这种动作在已定时间内完成,继承 FiniteTimeAction。
-         * @class ActionInterval
-         * @extends FiniteTimeAction
-         * @param {Number} d duration in seconds
-         */
-        export class _cocos_tween_actions_action_interval__ActionInterval extends _cocos_tween_actions_action__FiniteTimeAction {
-            protected MAX_VALUE: number;
-            protected _elapsed: number;
-            protected _firstTick: boolean;
-            protected _easeList: Function[];
-            protected _speed: number;
-            protected _repeatForever: boolean;
-            _repeatMethod: boolean;
-            protected _speedMethod: boolean;
-            constructor(d?: number);
-            getElapsed(): number;
-            initWithDuration(d: number): boolean;
-            isDone(): boolean;
-            _cloneDecoration(action: _cocos_tween_actions_action_interval__ActionInterval): void;
-            _reverseEaseList(action: _cocos_tween_actions_action_interval__ActionInterval): void;
-            clone(): _cocos_tween_actions_action_interval__ActionInterval;
-            /**
-             * @en Implementation of ease motion.
-             * @zh 缓动运动。
-             * @method easing
-             * @param {Object} easeObj
-             * @returns {ActionInterval}
-             * @example
-             * import { easeIn } from 'cc';
-             * action.easing(easeIn(3.0));
-             */
-            easing(easeObj: any): _cocos_tween_actions_action_interval__ActionInterval;
-            _computeEaseTime(dt: any): any;
-            step(dt: number): void;
-            startWithTarget(target: any): void;
-            reverse(): _cocos_tween_actions_action_interval__ActionInterval;
-            setAmplitudeRate(amp: any): void;
-            getAmplitudeRate(): number;
-            /**
-             * @en
-             * Changes the speed of an action, making it take longer (speed>1)
-             * or less (speed<1) time. <br/>
-             * Useful to simulate 'slow motion' or 'fast forward' effect.
-             * @zh
-             * 改变一个动作的速度,使它的执行使用更长的时间(speed > 1)<br/>
-             * 或更少(speed < 1)可以有效得模拟“慢动作”或“快进”的效果。
-             * @param {Number} speed
-             * @returns {Action}
-             */
-            speed(speed: number): _cocos_tween_actions_action__Action;
-            /**
-             * @en
-             * Get this action speed.
-             * @zh
-             * 返回此动作速度
-             * @return {Number}
-             */
-            getSpeed(): number;
-            /**
-             * @en
-             * Set this action speed.
-             * @zh
-             * 设置此动作速度
-             * @param {Number} speed
-             * @returns {ActionInterval}
-             */
-            setSpeed(speed: number): _cocos_tween_actions_action_interval__ActionInterval;
-            /**
-             * @en
-             * Repeats an action a number of times.
-             * To repeat an action forever use the CCRepeatForever action.
-             * @zh 重复动作可以按一定次数重复一个动作,使用 RepeatForever 动作来永远重复一个动作。
-             * @method repeat
-             * @param {Number} times
-             * @returns {ActionInterval}
-             */
-            repeat(times: number): _cocos_tween_actions_action_interval__ActionInterval;
-            /**
-             * @en
-             * Repeats an action for ever.  <br/>
-             * To repeat the an action for a limited number of times use the Repeat action. <br/>
-             * @zh 永远地重复一个动作,有限次数内重复一个动作请使用 Repeat 动作。
-             * @method repeatForever
-             * @returns {ActionInterval}
-             */
-            repeatForever(): _cocos_tween_actions_action_interval__ActionInterval;
-        }
-        /**
          * @en Enum for transition type.
          *
          * @zh 过渡类型。
          */
@@ -69744,6 +69634,7 @@
     import { AnimationMask, __private as ___private } from "cc/editor/new-gen-anim";
     import { CCON } from "cc/editor/serialization";
     export { Canvas as CanvasComponent, UIRenderer as RenderComponent, UIRenderer as UIRenderable, UIRenderer as Renderable2D, UITransform as UITransformComponent, Mask as MaskComponent, RichText as RichTextComponent, Sprite as SpriteComponent, UIMeshRenderer as UIModelComponent, LabelOutline as LabelOutlineComponent, Graphics as GraphicsComponent, UIStaticBatch as UIStaticBatchComponent, UIOpacity as UIOpacityComponent, Label as LabelComponent, MeshRenderer as ModelComponent, DirectionalLight as DirectionalLightComponent, Light as LightComponent, SphereLight as SphereLightComponent, SpotLight as SpotLightComponent, SkinnedMeshRenderer as SkinningModelComponent, SkinnedMeshBatchRenderer as BatchedSkinningModelComponent, SkinnedMeshUnit as SkinningModelUnit, Animation as AnimationComponent, AudioSource as AudioSourceComponent, Node as BaseNode, Camera as CameraComponent, ModelRenderer as RenderableComponent, Billboard as BillboardComponent, Line as LineComponent, ParticleSystem as ParticleSystemComponent, SkeletalAnimation as SkeletalAnimationComponent, Button as ButtonComponent, EditBox as EditBoxComponent, Layout as LayoutComponent, ProgressBar as ProgressBarComponent, ScrollBar as ScrollBarComponent, ScrollView as ScrollViewComponent, Slider as SliderComponent, Toggle as ToggleComponent, ToggleContainer as ToggleContainerComponent, Widget as WidgetComponent, PageView as PageViewComponent, PageViewIndicator as PageViewIndicatorComponent, SafeArea as SafeAreaComponent, UICoordinateTracker as UICoordinateTrackerComponent, BlockInputEvents as BlockInputEventsComponent } from "cc";
     import { Details as _Details } from "cc";
+    import { codec } from "cc/editor/particle-system-2d-utils";
     export {};
 }


/**
* !#en set/get time scale for tween
* !#zh 设置/读取 tween 的 time scale (时间缩放参数)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use @en and @zh instead

* !#en set/get time scale for tween
* !#zh 设置/读取 tween 的 time scale (时间缩放参数)
* @property timeScale
* @type {Number}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to specify property name and type, it's automatically detected

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update all API comments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to specify property name and type, it's automatically detected

改好了. 但是我发现你们原先的代码里 在这方面也有一些问题. 比如有的方法会写@method @return , 有的不写.

cocos/tween/actions/action-interval.ts Outdated Show resolved Hide resolved
cocos/tween/tween.ts Show resolved Hide resolved
cocos/tween/tween.ts Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants