- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试旋转箭头以跟随手指移动,但它的表现很奇怪。它绝对不是跟随它。我试图在 touchesMoved 中做到这一点。我试着这样做:
var fingerLocation = CGPoint()
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
for touch: AnyObject in touches {
fingerLocation = touch.locationInNode(self)
let currentOrient = arrow.position
let angle = atan2(currentOrient.y - fingerLocation.y, currentOrient.x - fingerLocation.y)
let rotateAction = SKAction.rotateToAngle(angle + CGFloat(M_PI*0.5), duration: 0.0)
arrow.runAction(rotateAction)
}
}
也试过这个:
var fingerLocation = CGPoint()
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
for touch: AnyObject in touches {
fingerLocation = touch.locationInNode(self)
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
var radians = atan2(fingerLocation.x, fingerLocation.y)
arrow.zRotation = -radians
}
我也试过 SKConstraint.orientToPoint 但也没有成功。我究竟做错了什么?类似问题的每个答案都是建议 atan2,但它似乎对我不起作用。
最佳答案
如果你想将 Sprite 旋转到触摸位置,它应该很简单:
let touchLocation = touch.locationInNode(self)
var dx = hero.position.x - positionInScene.x;
var dy = hero.position.y - positionInScene.y ;
var angle = atan2(dy,dx) + CGFloat(M_PI_2)
hero.zRotation = angle
当我尝试时它起作用了,所以它可以让您基本了解从哪里开始。或者我误解了你想要达到的目标......
编辑:
目前,如果您尝试将角度转换为度数,您将得到 -90 到 270 度范围内的角度。它描述了here为什么。如果您想使用 0 到 360 度范围内的角度,您可以将上面的代码更改为:
var dx = missile.position.x - positionInScene.x ;
var dy = missile.position.y - positionInScene.y;
var angleInRadians = atan2(dy,dx) + CGFloat(M_PI_2)
if(angleInRadians < 0){
angleInRadians = angleInRadians + 2 * CGFloat(M_PI)
}
missile.zRotation = angleInRadians
var degrees = angleInRadians < 0 ? angleInRadians * 57.29577951 + 360 : angleInRadians * 57.29577951
这是调试数据的结果:
关于ios - 节点旋转不跟随手指,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32417157/
我用 cocos2d 制作了我的第一个应用程序,所以我在这里很新 我的第一个问题: 我不会让物体(船)跟随我的手指。 -(void) ccTouchMoved:(UITouch *)touch wit
如果某人将右手压在扫描仪的玻璃上进行扫描,结果将如下所示: (没有橙色和白色注释)。我们如何确定某人的 2D:4D ratio从他们的手的图像? 最佳答案 您已经标记了这个很棒的 opencv - 我
我的 View Controller 中有几个 UIScrollView。我想覆盖一个通过 UIPanGestureRecognizer 捕获 2 根手指滑动的 View ,它不会记录 UIScrol
现在这真是令人困惑...在不离开页面的情况下更新 mysql 数据库...我有 3 位代码。 head 标签中的 javascript、body 中的操作按钮以及要在另一个页面上执行的代码。以下是三个
我有这段代码是从 Style clipboard in flutter 得到的 showMenu( context: context, // TODO: Positio
我是一名优秀的程序员,十分优秀!