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
merged 6 commits into from Nov 14, 2019
Merged

fixed cc.RotateTo error #5717

merged 6 commits into from Nov 14, 2019

Conversation

zhefengzhang
Copy link
Contributor

issues: https://github.com/cocos-creator/2d-tasks/issues/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;
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

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

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

这跟rotation有什么关系么

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

@holycanvas
Copy link
Contributor

holycanvas commented Nov 11, 2019

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

@zhefengzhang
Copy link
Contributor Author

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

@2youyou2
Copy link
Contributor

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

cc.macro.ROTATE_ACTION_CCW 的添加请参考 https://github.com/cocos-creator/2d-tasks/issues/1554

@holycanvas
Copy link
Contributor

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

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

@zhefengzhang
Copy link
Contributor Author

zhefengzhang commented Nov 11, 2019

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

@zhefengzhang
Copy link
Contributor Author

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

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

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

@@ -881,6 +881,7 @@ cc.RotateTo = cc.Class({
extends: cc.ActionInterval,

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

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

没有删掉。。。

@holycanvas holycanvas merged commit f541f4e into cocos:v2.2.1-release Nov 14, 2019
@zhefengzhang zhefengzhang deleted the v2.2.1-release-rotate-to branch March 17, 2020 05:50
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