-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 calculation delta of node angle #6102
Conversation
_onTouchMoved 里也有相关 delta 的逻辑,需要同步修改一下吗 |
// calculation delta of node angle | ||
_getLocalAxisAlignDelta (delta) { | ||
let worldRot = cc.quat(); | ||
this.node.getWorldRotation(worldRot); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里如果耗性能的话,是不是可以先判断下,如果 angle 为 0,就不做这个处理了
一般也很少人回去旋转 scrollview
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@2youyou2 这里是否能通过 this.node._worldMatDirty 来判断是否有旋转?如果 _worldMatDirty 为 true 时,在 TOUCH_MOVE 触发的时候获取的 _worldMatDirty 是否还是 true,还是说已经被重置为 false 了
_getLocalAxisAlignDelta (delta) {
if (this.node._worldMatDirty) {
this.node.getWorldRotation(_worldRot);
}
let oriDelta = cc.v3(delta.x, delta.y, 0);
let deltaMove = cc.v2();
if (this.horizontal) {
Vec3.transformQuat(_tempVec3, Vec3.RIGHT, _worldRot);
deltaMove.x = oriDelta.dot(_tempVec3);
}
if (this.vertical) {
Vec3.transformQuat(_tempVec3, Vec3.UP, _worldRot);
deltaMove.y = oriDelta.dot(_tempVec3);
}
return deltaMove;
},
``
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不行啊,_worldMatDirty 什么时候都有可能被重置掉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你有没有比较好的办法呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
把 delta 转到 local 坐标系下就好了嘛
_onTouchMoved 中的 |
_getLocalAxisAlignDelta (delta) { | ||
let worldRot = cc.quat(); | ||
this.node.getWorldRotation(worldRot); | ||
let oriDelta = cc.v3(delta.x, delta.y, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要一直 new 对象
@@ -1011,8 +1011,15 @@ let ScrollView = cc.Class({ | |||
this._gatherTouchMove(deltaMove); | |||
}, | |||
|
|||
// Contains node angle calculations | |||
_getLocalAxisAlignDelta (touch) { | |||
let point = this.node.convertToNodeSpaceAR(touch.getLocation()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以定义几个临时变量传到 convertToNodeSpaceAR
里面作为返回值
let _point = this.node.convertToNodeSpaceAR(touch.getLocation(), _tempPoint); | ||
let _prevPoint = this.node.convertToNodeSpaceAR(touch.getPreviousLocation(), _tempPrevPoint); | ||
return _point.sub(_prevPoint); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该不用创建 _point _prevPoint 变量了
_tempPoint _tempPrevPoint 就是输出变量
dc227b8
to
3a98a66
Compare
Re:
cocos-creator/2d-tasks#2399
/issues/6654
Changes: