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

fixed cc.RotateTo error #5717

Merged

Conversation

@Jno1995
Copy link
Contributor

Jno1995 commented Nov 11, 2019

issues: cocos-creator/2d-tasks#2063

用户传入的是 rotation 的值,而引擎内部使用 rotation 进行旋转变换需要把 rotation 转成 angle 才能正确使用。
之前 cc.RotateTo 内部没有对用户传入的 rotation 转换成 angle。

@@ -895,7 +895,7 @@ cc.RotateTo = cc.Class({
*/
initWithDuration:function (duration, dstAngle) {
if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
this._dstAngle = dstAngle;
this._dstAngle = -dstAngle;

This comment has been minimized.

Copy link
@holycanvas

holycanvas Nov 11, 2019

Contributor

为什么转成负的,就变成angle了呢

This comment has been minimized.

Copy link
@Jno1995

Jno1995 Nov 11, 2019

Author Contributor

因为在 CCNode 中 rotation 的设计就是这样的。
image

This comment has been minimized.

Copy link
@holycanvas

holycanvas Nov 11, 2019

Contributor

用户没有用rotation呀,他只设置了angle

node.angle=22;
node.runAction(cc.rotateTo(1.0, -22));

这跟rotation有什么关系么

This comment has been minimized.

Copy link
@Jno1995

Jno1995 Nov 11, 2019

Author Contributor

是的,和 rotation 没有关系,拿它说只是因为 CCNode 上还是用它来表示旋转角度。
这里之所以要 * -1,是因为 2.1 升级之后 angle 带来的改动。用户传入的 end_degree 需要 * -1 才能变成 angle,才能在 2.1 之后的版本中正确使用。

@holycanvas

This comment has been minimized.

Copy link
Contributor

holycanvas commented Nov 11, 2019

应该不是这里的问题,改成负值应该也有问题
image,如果用户修改了旋转的方向,还是会等于0

@Jno1995

This comment has been minimized.

Copy link
Contributor Author

Jno1995 commented Nov 11, 2019

我改了之后试了下,表现结果是正确的。

@2youyou2

This comment has been minimized.

Copy link
Contributor

2youyou2 commented Nov 11, 2019

不用改啊,让他设置 cc.macro.ROTATE_ACTION_CCW 来决定旋转方向是逆时针还是顺时针。
而且 rotation 都已经废弃了,angle 的方向才是正道,逆时针才是现在的正值期望方向

cc.macro.ROTATE_ACTION_CCW 的添加请参考 cocos-creator/2d-tasks#1554

@holycanvas

This comment has been minimized.

Copy link
Contributor

holycanvas commented Nov 11, 2019

不用改啊,让他设置 cc.macro.ROTATE_ACTION_CCW 来决定旋转方向是逆时针还是顺时针。

他现在是顺时针旋转,但是因为两个值相加为0,所以什么事都没发生,这样的表现应该不太正常吧?
image

@Jno1995

This comment has been minimized.

Copy link
Contributor Author

Jno1995 commented Nov 11, 2019

和设置顺逆时针没关系,用户反馈的是当前(默认顺时针)cc.RotatoTo(1, -22)执行之后,节点的角度表现不是 -22 该有的表现而是 22 的。所以是 rotateTo 有问题,而不是别的。
目前我就看到 rotateTo 没有对用户输入的 value 做类似 CCNode 那边的 * -1 转换,结果导致计算结果错误。

Jno1995 added 3 commits Nov 14, 2019
This reverts commit f831a18.
@Jno1995

This comment has been minimized.

Copy link
Contributor Author

Jno1995 commented Nov 14, 2019

第一次的修改,从作用上是和开发者的思路一致的,也是取负转换,但是当时没有考虑到用户改变了转向之后会导致问题。cc.rotateBy 上也有类似处理,它采用的是:

deltaAngle *= cc.macro.ROTATE_ACTION_CCW ? 1 : -1;

考虑到目前 startWithTarget 现在的代码设计,我觉得直接修改在 startWithTarget 中,会更直接一点。

@holycanvas holycanvas requested a review from 2youyou2 Nov 14, 2019
@@ -881,6 +881,7 @@ cc.RotateTo = cc.Class({
extends: cc.ActionInterval,

ctor:function (duration, dstAngle) {
dstAngle *= cc.macro.ROTATE_ACTION_CCW ? 1 : -1;

This comment has been minimized.

Copy link
@holycanvas

holycanvas Nov 14, 2019

Contributor

不用加这句吧,你加了这句,下面这句不就又回到最开始的状态了么

This comment has been minimized.

Copy link
@Jno1995

Jno1995 Nov 14, 2019

Author Contributor

没有删掉。。。

Jno1995 added 2 commits Nov 14, 2019
 into v2.2.1-release-rotate-to
@holycanvas holycanvas merged commit f541f4e into cocos-creator:v2.2.1-release Nov 14, 2019
1 check passed
1 check passed
ci/circleci: test Your tests passed on CircleCI!
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.