我试图让精灵永远上下移动,我尝试使用“if语句”检查位置是否……而不是再次向上移动.但它不起作用. 我真的很感激一些帮助,谢谢! 这是代码. var Ground = SKSpriteNode()var Ground2 = SKSpri
我真的很感激一些帮助,谢谢!
这是代码.
var Ground = SKSpriteNode() var Ground2 = SKSpriteNode() override func didMoveToView(view: SKView) { Move() } func Move(){ let action = SKAction.moveToY(self.frame.height / 2 - 360, duration: 5.0) Ground.runAction(SKAction.repeatActionForever(action)) let action2 = SKAction.moveToY(self.frame.height / 2 + 140, duration: 5.0) Ground2.runAction(SKAction.repeatActionForever(action2)) }您可以使用动作序列:
override func didMoveToView(view: SKView) { let sprite = SKSpriteNode(color: SKColor.purpleColor(), size: CGSize(width: 100, height: 10)) sprite.position = CGPoint(x: CGRectGetMidX(frame), y: CGRectGetMidY(frame)) addChild(sprite) let moveUp = SKAction.moveByX(0, y: 200, duration: 2) let sequence = SKAction.sequence([moveUp, moveUp.reversedAction()]) sprite.runAction(SKAction.repeatActionForever(sequence), withKey: "moving") }