2017-04-27 1 views
2

Das ist mein Code für den Test ist:Warum repeatForever nicht in spritekit arbeiten, 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) 

Diese Wolke nur einmal ausgeführt wird, sagen Sie mir bitte die Lösung bitte

+0

Sobald Sie zu 'CGPoint (x: -cloud1.size.width/2, y: cloud1.position.y) 'gewechselt sind, wo erwarten Sie weiter zu gehen? – matt

+0

Ich möchte nur, dass es sich wieder von links nach rechts bewegt. keine Idee –

+0

Was würde es dazu bringen? Ich sehe in deiner Sequenz keine Aktion, die das tut. Sie sagen ihm, dass er sich nach links bewegen soll und das ist alles, was Sie ihm sagen. – matt

Antwort

3

auf der Grundlage Ihrer Frage, ich Ich denke, ich könnte eine Lösung haben.

der Grund, warum es sich nicht bewegt, nachdem er ein bestimmtes Ziel erreicht ist, weil Sie moveTo verwenden. Hier ist ein kleines Beispiel, das ich basierend auf dem von Ihnen bereitgestellten Code erstellt habe.

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) 

hoffentlich löst Ihr Problem!