gpt4 book ai didi

ios - 添加另一个背景图像以在玩游戏时更改背景

转载 作者:行者123 更新时间:2023-11-29 00:47:43 24 4
gpt4 key购买 nike

func createBackgrounds() {
for i in 0...2 {
let bg = SKSpriteNode(imageNamed: "BG Day")
bg.name = "BG"
bg.zPosition = 0;
bg.anchorPoint = CGPoint(x: 0.5, y: 0.5)
bg.position = CGPoint(x: CGFloat(i) * bg.size.width, y: 0)
self.addChild(bg)
}
}

如果我想在 2 分钟后添加另一个背景图像到 BG Night,我该如何在 swift 2 中编写代码?

最佳答案

以后可以使用SKAction.runBlock来运行一些代码

class GameScene: SKScene {

var background: SKSpriteNode?

override func didMoveToView(view: SKView) {
super.didMoveToView(view)
changeBackgroundIn2Mintues()
self.background = SKSpriteNode(imageNamed: "OLD_BG_IMAGE_NAME")
}

private func changeBackgroundIn2Mintues() {

let wait = SKAction.waitForDuration(60 * 2)
let changeBG = SKAction.runBlock { [unowned self] in
self.background?.removeFromParent()
self.background = SKSpriteNode(imageNamed: "NEW_BG_IMAGE_NAME")
}
let sequence = SKAction.sequence([wait, changeBG])
self.runAction(sequence)

}
}

关于ios - 添加另一个背景图像以在玩游戏时更改背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38448908/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com