我正在嘗試製作一個遊戲,當精靈被對象擊中時,它總是會向右移動。然而,由於Sprite不斷旋轉,零弧度與Sprite一起旋轉,因此如果精靈朝左並擊中對象,則我的計算大小將朝相反的方向移動。即使零點朝向左邊,是否有一種方法可以使量值的方向始終指向右側?在旋轉雪碧時保持矢量常量的方向
// referencePoint = upper right corner of the frame
let rightTriangleFinalPoint:CGPoint = CGPoint(x: referencePoint.x, y: theSprite.position.y)
let theSpriteToReferenceDistance = distanceBetweenCGPoints(theSprite.position, b: referencePoint)
let theSpriteToFinalPointDistance = distanceBetweenCGPoints(theSprite.position, b: rightTriangleFinalPoint)
let arcCosineValue = theSpriteToFinalPointDistance/theSpriteToReferenceDistance
let angle = Double(acos(arcCosineValue))
let xMagnitude = magnitude * cos(angle)
let yMagnitude = (magnitude * sin(angle))/1.5
你如何推動精靈?它是使用力量,SKA或其他方式嗎? – Gliderman
我正在使用applyImpulse來移動Sprite @Gliderman –