gpt4 book ai didi

swift - 围绕非 .anchorPoint 的内部点旋转 SkSpriteNode

转载 作者:行者123 更新时间:2023-11-30 10:10:30 25 4
gpt4 key购买 nike

所以我使用此代码顺时针或逆时针旋转对象。

    override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {

let touch = touches.first as UITouch!
let touchPosition = touch.locationInNode(self)
let newRotationDirection : rotationDirection = touchPosition.x < CGRectGetMidX(self.frame) ? .clockwise : .counterClockwise

if currentRotationDirection != newRotationDirection && currentRotationDirection != .none {
reverseRotation()
currentRotationDirection = newRotationDirection
}
else if (currentRotationDirection == .none) {
setupRotationWith(direction: newRotationDirection)
currentRotationDirection = newRotationDirection
}
}



func reverseRotation(){
let oldRotateAction = ship.actionForKey("rotate")
let newRotateAction = SKAction.reversedAction(oldRotateAction!)
ship.runAction(newRotateAction(), withKey: "rotate")
}



func stopRotation(){
ship.removeActionForKey("rotate")
}



func setupRotationWith(direction direction: rotationDirection){
let angle : CGFloat = (direction == .clockwise) ? CGFloat(M_PI) : -CGFloat(M_PI)
let rotate = SKAction.rotateByAngle(angle, duration: 2)
let repeatAction = SKAction.repeatActionForever(rotate)
ship.runAction(repeatAction, withKey: "rotate")
}

我的问题是,这会围绕 SKSpriteNode 的 anchor 创建顺时针或逆时针旋转。

但是,我希望该对象绕 SKSprite 内部的另一个点旋转(类似于 Sprite 图像底部向上 4/5 的位置)。我假设我不能使用通过 CGPointMake 定义的设定点,因为我希望 Sprite 在屏幕上独立移动,但这行不通?

有人有什么建议吗?

最佳答案

您是否尝试过将 Sprite 的 anchorPoint 属性设置为您希望 Sprite 围绕其旋转的点?

ship.anchorPoint = CGPoint(x: 0, y: 4/5)

这是您要找的吗?

关于swift - 围绕非 .anchorPoint 的内部点旋转 SkSpriteNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33175072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com