我有兩個從我的屏幕頂部相互平行的點,它們將與底部的兩個可以隨觸摸旋轉的圓相匹配。我讓他們產生這樣的:如何逐漸加速下降節點隨着時間的推移?
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
runAction(SKAction.repeatActionForever(
SKAction.sequence([
SKAction.runBlock(generateDots),
SKAction.waitForDuration(1.0)])))
}
func generateDots() {
let count = 2
let index=Int(arc4random_uniform(UInt32(count)))
let dots = SKSpriteNode(imageNamed: "Color\(index+1)")
dots.physicsBody = SKPhysicsBody(circleOfRadius: 10)
dots.physicsBody?.dynamic = true
dots.physicsBody?.affectedByGravity = false
for i in 0..<2 {
dots.physicsBody?.categoryBitMask = UInt32(0x1 << index)
dots.physicsBody?.contactTestBitMask = UInt32(0x1 << index)
}
addChild(dots)
dots.size = CGSizeMake(45, 45)
dots.position = CGPointMake(150, 400)
dots.runAction(
SKAction.moveByX(0, y: -900,
duration: NSTimeInterval(11.5)))
}
}
有什麼辦法來逐漸加快他們要麼正在下降的速度有多快或逐步改變waitForDuration
,這樣隨着時間的推移它會產生一個節點,每3秒,然後2秒,然後1秒等等?
這可能是你要找的東西http://stackoverflow.com/questions/34624292/change-time-interval-in-skaction-waitforduration-as-game-goes-on – 0x141E
非常感謝你!還有一種方法可以加速節點嗎? – KeepItSimple
爲「moveByX」動作的持續時間參數定義一個變量,並在「遞歸」方法中減少該變量。 – 0x141E