[我试图制作一个像SpriteKit(Xcode 7 beta)中的Doodle Jump这样的垂直无尽奔跑者,但无法弄清楚如何不断向上移动Node。
override func didMoveToView(view: SKView) {
makeBackground()
// Bubble
let bubbleTexture = SKTexture(imageNamed: "bubble.png")
bubble = SKSpriteNode(texture: bubbleTexture)
bubble.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))
bubble.physicsBody = SKPhysicsBody(circleOfRadius: bubbleTexture.size().height/2)
bubble.physicsBody!.dynamic = false
bubble.physicsBody!.allowsRotation = false
let float = SKAction.moveToY(+yScale, duration: 0.2)
bubble.SKAction.repeatActionForever(runAction(float))
self.addChild(bubble)
}
恰好在回答完您的最新帖子后,在这里看到您的帖子;而且我想我也会回答。
您只需要以下内容,它告诉SKAction
将动作重复作为参数:
let float = SKAction.repeatActionForever(SKAction.moveToY(+yScale, duration: 0.2))
bubble.runAction(float)
作为旁注:
在Swift中,可以将您的变量命名为float
。但是,由于存在一个一流的变量float
,因此人们对此一无所知。但是在Swift中,float是大写的。因此,这里没有冲突。但是,为了避免我们的额头不时被高级程序员抓住,我们可以将您的操作命名为“ floating”,由于“ -ing],我认为它很合适>”(连续动词形式或gerund)传达一种动作感。