为什么反复在spritekit中不工作,swift3



这是我的测试代码:

    let cloud1 = SKSpriteNode(imageNamed: "cloud1")
    cloud1.position = CGPoint(x: size.width + cloud1.size.width/2, y: size.height / 2)
    addChild(cloud1)
    let wait = SKAction.wait(forDuration: 0.25)
    let actionMove = SKAction.move(to: CGPoint(x: -cloud1.size.width/2, y: cloud1.position.y), duration: 2.0)
    let sequence = SKAction.sequence([actionMove, wait])
    let repeatAction = SKAction.repeatForever(sequence)
    cloud1.run(repeatAction)

这个云仅运行一次,请告诉我解决方案

基于您的问题,我认为我可能有解决方案。

为什么它在到达某个目的地之后没有移动的原因是因为您使用的是moveTo。这是我根据您提供的代码进行的一个示例。

var cloudSpeed = CGFloat(12) //this can be any number you want, the higher the faster

    let cloud1 = SKSpriteNode(imageNamed: "cloud1")
    cloud1.position = CGPoint(x: size.width/2, y: size.height / 2)
    addChild(cloud1)
    let wait = SKAction.wait(forDuration: 0.25)
    let actionMove = SKAction.move(by: CGVector(dx:-10 * ballSpeed, dy:0), duration: 1) //experiment with the dx value. If you want the cloud to travel from right to left make it a negative
    let sequence = SKAction.sequence([actionMove, wait])
    let repeatAction = SKAction.repeatForever(sequence)
    cloud1.run(repeatAction)

希望这能解决您的问题!

最新更新