简体   繁体   English

Swift-SKAction序列遇到问题

[英]Swift - Trouble with SKAction sequence

I'm trying to move my background image down and then after a 3 second delay, move it back up the screen. 我正在尝试将背景图片向下移动,然后在3秒钟的延迟后,将其向上移回屏幕。 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. 根据您的anchorPoint,第一个操作是正确的。 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) 如果您想看到BG回来,那么您错了Y位置,否则您的BG放在屏幕的顶部(因此不可见)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM