当我在节点上运行loop
时,一切正常,节点移动正确。但是当next
动作中断时next
到达屏幕的左边界(中途)时,我会运行循环。我认为复制有问题。谢谢!
func moveBackground (name: String, speed: CGFloat = 0.01) {
guard let node = childNode(withName: name) as? SKTileMapNode else {
fatalError("\(name) node not loaded")
}
let width = node.frame.size.width
let startPositionX = width
node.position = CGPoint(x: startPositionX , y: 0)
let next = node.copy() as! SKTileMapNode
next.tileSet = node.tileSet
next.position = CGPoint(x: startPositionX , y: 0)
self.addChild(next)
let distance = width * 2
let duration = TimeInterval(speed * distance)
let moveAction = SKAction.moveBy(x: -distance, y: 0, duration: duration)
let resetAction = SKAction.moveTo(x: startPositionX, duration: 0)
let sequence = SKAction.sequence([moveAction, resetAction])
let loop = SKAction.repeatForever(sequence)
//node.run(loop)
next.run(loop)
}