SKAction.moveToX 重复值更改

SKAction.moveToX repeat with value change

我希望能够在每移动 20 个像素时暂停移动球我尝试了这个但什么也没做,球停留在它开始的地方它不会移动到屏幕的尽头,我知道我没有放 waitForDuration ,因为我想检查它是否会移动

func spwan()
{
    let ball:SKSpriteNode = SKScene(fileNamed: "Ball")?.childNodeWithName("ball") as! SKSpriteNode
    ball.removeFromParent()
    self.addChild(ball)
    ball.name = "spriteToTrack"
    ball.zPosition = 0
    ball.position = CGPointMake(1950, 1000)
    var num:CGFloat = ball.position.x
    let a1 = SKAction.moveToX(num - 20, duration: 10)
    // i want to get to -50 let a1 = SKAction.moveToX(-50 , duration: 10)       
    let minus = SKAction.runBlock{
        num -= 20
    }
    let sq1 = SKAction.sequence([a1,minus])
    ball.runAction(SKAction.repeatAction(sq1, count: 10)      
}

在上面的代码中,球应该至少移动 20 个像素,但 10 秒内移动 20 个像素可能看起来像是静止的。无论如何,我认为你使用 moveToX 而不是 moveBy: 使事情变得过于复杂了,所以(稍微调整一下)你可能最好使用这样的东西:

func spawn() {
    let x: CGFloat = 1950
    let xDelta: CGFloat = -20
    let xDestination: CGFloat = -50
    let repeats = Int((x - xDestination)/fabs(xDelta))

    let move = SKAction.moveBy(CGVectorMake(xDelta, 0), duration: 2) // made it a lot quicker to show that stuff is happening
    move.timingMode = .EaseInEaseOut

    let ball:SKSpriteNode = SKScene(fileNamed: "Ball")?.childNodeWithName("ball") as! SKSpriteNode
    ball.removeFromParent()
    ball.name = "spriteToTrack"

    ball.position = CGPointMake(x, 1000)

    addChild(ball)
    ball.runAction(SKAction.repeatAction(move, count: repeats))
}