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

add tween syntactic sugar #6327

Merged
merged 4 commits into from Mar 18, 2020
Merged

Conversation

2youyou2
Copy link
Contributor

@2youyou2 2youyou2 commented Mar 13, 2020

Re: cocos/2d-tasks#2604

Changes:

  • add tween syntactic sugar
    • bezierTo
    • bezierBy
    • flipX
    • flipY
    • blink

利用泛型完善了 tween 的代码提示机制
image

image

@@ -498,6 +500,10 @@ var Component = cc.Class({
},

_onPreDestroy () {
if (ActionManagerExist) {
cc.director.getActionManager().removeAllActionsFromTarget(this);
Copy link
Contributor Author

@2youyou2 2youyou2 Mar 13, 2020

Choose a reason for hiding this comment

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

节点已经在 _onPreDestroy 里停止 action 了。
我在考虑是不是需要在 CCObject 里面做,不过这样很多无关的也会去判断了。

Copy link
Member

@jareguo jareguo Mar 14, 2020

Choose a reason for hiding this comment

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

只有组件和节点才需要吧……

*/
tintBy (duration, color, opts) {
return this.by(duration, { color }, opts);
}
Copy link
Member

@jareguo jareguo Mar 14, 2020

Choose a reason for hiding this comment

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

flipX, Y,还有后面这些单行实现的封装感觉意义不大啊,他想要代码这么抽象的话自己封装一个小函数也行

Copy link
Contributor Author

@2youyou2 2youyou2 Mar 16, 2020

Choose a reason for hiding this comment

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

原 action 有的都可以有,已经有用户抱怨这些函数为什么没了

Copy link
Member

@jareguo jareguo Mar 16, 2020

Choose a reason for hiding this comment

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

这种就一行代码的,解释下吧,不然历史包袱都去不掉了

Copy link
Contributor Author

@2youyou2 2youyou2 Mar 16, 2020

Choose a reason for hiding this comment

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

这些都是对 node 的扩展,要不加个 tween-extends-node.js,做个单独的扩展模块?
核心 tween 仍然是很干净的

* !#zh 按照贝塞尔路径设置目标的 position 属性。
* @method bezierTo
* @param {number} duration
* @param {[cc.Vec2, cc.Vec2, cc.Vec2]} controls
Copy link
Member

@jareguo jareguo Mar 14, 2020

Choose a reason for hiding this comment

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

这个数组解释下?为什么不拆分成三个参数?

Copy link
Contributor Author

@2youyou2 2youyou2 Mar 16, 2020

Choose a reason for hiding this comment

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

保持原有的接口。。

Copy link
Member

@jareguo jareguo Mar 16, 2020

Choose a reason for hiding this comment

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

感觉拆开好像更清晰一些?

Copy link
Contributor Author

@2youyou2 2youyou2 Mar 18, 2020

Choose a reason for hiding this comment

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

那拆开吧

@@ -498,6 +500,10 @@ var Component = cc.Class({
},

_onPreDestroy () {
if (ActionManagerExist) {
cc.director.getActionManager().removeAllActionsFromTarget(this);
Copy link
Member

@jareguo jareguo Mar 14, 2020

Choose a reason for hiding this comment

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

只有组件和节点才需要吧……

* !#zh 按照贝塞尔路径设置目标的 position 属性。
* @method bezierBy
* @param {number} duration
* @param {[cc.Vec2, cc.Vec2, cc.Vec2]} controls
Copy link
Contributor

@holycanvas holycanvas Mar 16, 2020

Choose a reason for hiding this comment

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

这样写,d.ts能正常识别么,cc.Vec2[] 会不会好一点

Copy link
Contributor Author

@2youyou2 2youyou2 Mar 16, 2020

Choose a reason for hiding this comment

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

这么写是强制传 3 个 cc.Vec2 的 array, cc.Vec2[] 没有限制个数

type AllowedNames<Base, Type> = FlagExcludedType<Base, Type>[keyof Base];
type KeyPartial<T, K extends keyof T> = { [P in K]?: T[P] };
type OmitType<Base, Type> = KeyPartial<Base, AllowedNames<Base, Type>>;
type ConstructorType<T> = OmitType<T, Function>;
Copy link
Contributor

@holycanvas holycanvas Mar 18, 2020

Choose a reason for hiding this comment

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

ts就是这点不好,看不懂

Copy link
Contributor Author

@2youyou2 2youyou2 Mar 18, 2020

Choose a reason for hiding this comment

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

你仔细看下上面的链接就懂了,^_^

@holycanvas holycanvas merged commit 0e18c25 into cocos:v2.3.3-release Mar 18, 2020
1 check passed
@2youyou2 2youyou2 mentioned this pull request Aug 19, 2020
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