I'm trying to move my background image down and then after a 3 second delay, move it back up the screen. And I want this to occur forever.
It slides down the screen perfectly fine, but then nothing else happens. Can anyone see what I'm doing wrong here?
override func didMoveToView(view: SKView) {
background.anchorPoint = CGPoint(x: 0, y: 0)
background.size = CGSize(width: frame.size.width, height: frame.size.height)
background.name = "bg"
addChild(background)
let moveBG1 = SKAction.moveToY(-(size.height), duration: 3.0)
let moveBGback = SKAction.moveToY(size.height, duration: 3.0)
runAction(SKAction.repeatActionForever(
SKAction.sequence([
SKAction.runAction(moveBG1, onChildWithName: "bg"),
SKAction.waitForDuration(3.0),
SKAction.runAction(moveBGback, onChildWithName: "bg")
])
))
According with your anchorPoint, the first action is correct. As nickfalk write to you, the second action must to be:
let moveBGback = SKAction.moveToY(0, duration: 3.0)
if you want to see your BG come back, so you have wrong the Y position, otherwise your BG is putted at the TOP of the screen (so not visible)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.