你如何让斯威夫特等待被执行SKAction?

问题描述 投票:0回答:2

我有以下的银行代码,但是,当我在Xcode模拟器中运行它,它跳过直接到“我不相信我们曾经见过面”。如何使首先被执行斯威夫特等待“欢迎”?

import SpriteKit
import GameplayKit

class GameScene: SKScene {

override func didMove(to view: SKView) {

    // Get label node from scene and store it for use later

    let animateList = SKAction.sequence([SKAction.fadeIn(withDuration: 1.0), SKAction.wait(forDuration: 2.0), SKAction.fadeOut(withDuration: 1.0)])

    let startScreen = SKLabelNode(fontNamed: "Helvetica Neue UltraLight")
    startScreen.text = "Welcome"
    startScreen.fontSize = 100.0
    startScreen.fontColor = SKColor.white
    startScreen.position = CGPoint(x: self.frame.midX, y: self.frame.midY)
    self.addChild(startScreen)
    startScreen.alpha = 0.0

    startScreen.run(animateList)

    startScreen.text = "I don't belive we have met before"

    startScreen.run(animateList)



    }


}
ios swift swift3 sprite-kit
2个回答
3
投票

与其说startScreen.run()的,叫startScreen.run(_:completion),做你想要的SKActions已完成处理器中运行之后做的事情。见documentation

startScreen.run(animateList, completion: {
    self.startScreen.text = "I don't belive we have met before"
    self.startScreen.run(animateList)
})

0
投票

您可以使用一个计时器,将等待要执行这样的内容:

 _ = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false) { _ in
   // do whatever you want after 1 second.
    }
© www.soinside.com 2019 - 2024. All rights reserved.