gpt4 book ai didi

ios - Swift/SpriteKit 帮助 : Increase CGFloat continuously to allow continuous rotation around a fixed point

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

我正在使用苹果的 SpriteKit 和 Swift 制作一个简单的游戏,并且遇到了问题。我试图让桨节点(paddle)围绕圆内的固定节点(anchorNode)连续旋转;但是,我无法弄清楚如何使桨节点(paddle)继续围绕定点节点(anchorNode)旋转,因为 SKAction.rotateByAngle 语句中的约束使其在一定时间/旋转后结束。

非常感谢任何帮助!

这是我的引用代码:

    //Setting up anchor Node

anchorNode.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))
anchorNode.size.height = (self.frame.size.height / 1000)
anchorNode.size.width = anchorNode.size.height
self.addChild(anchorNode)


//Setting up achor Node's physucs

anchorNode.physicsBody = SKPhysicsBody(circleOfRadius: (circle.frame.size.height / 1000))
anchorNode.physicsBody?.dynamic = false
anchorNode.physicsBody?.affectedByGravity = false
anchorNode.physicsBody?.friction = 0


//Making the anchor Node rotate

let rotate = SKAction.rotateByAngle(CGFloat(3.14), duration: NSTimeInterval(1.5))
anchorNode.runAction(rotate)



//Setting up the paddle node

paddle.position = CGPointMake((circle.frame.width / 2), 0)
paddle.size.height = (self.frame.size.height / 50)
paddle.size.width = (self.frame.size.width / 7)

anchorNode.addChild(paddle)

最佳答案

尝试添加此代码。

override func update(currentTime: NSTimeInterval) {
//How to make it spin
let speed = CGFloat(5)
let degreeRotation = CDouble(speed) * M_PI / 180
paddle.zRotation -= CGFloat(degreeRotation)
}

关于ios - Swift/SpriteKit 帮助 : Increase CGFloat continuously to allow continuous rotation around a fixed point,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31570249/

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