gpt4 book ai didi

ios - Spritekit 中的新场景没有显示任何内容?

转载 作者:行者123 更新时间:2023-11-30 11:12:45 25 4
gpt4 key购买 nike

我有 GameScene,并且在触摸的节点上,它会转到一个名为 PlayScene 的新场景。此操作已成功完成,但我添加到 PlayScene 的任何子节点都不会显示。不过,我可以更改新场景中的背景颜色。

这是我在 GameScene 中的内容:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let location = touches.first?.location(in: self)
let nodeTouched = atPoint(location!)

if nodeTouched.name == "playButton" {
print("Play Button Pressed")
let playScreenTransition = SKTransition.fade(with: UIColor(red: 35/255, green: 161/255, blue: 234/255, alpha: 1.0), duration: 0.5)

self.view?.presentScene(PlayScene(size: screenSize), transition: playScreenTransition)
vibrateGenLight.impactOccurred()
}
}

在 PlayScene 中:

class PlayScene: SKScene{

//UI Elements
let background = SKSpriteNode(imageNamed: "Background")
let stickyBlock = SKSpriteNode(imageNamed: "StickyBlock")

override func didMove(to view: SKView) {
print("In PlayScene")
let xy = 0.5;
anchorPoint = CGPoint(x: xy, y: xy)

self.addChild(background)

self.addChild(stickyBlock)
}
}

在 GameViewController 中:

class GameViewController: UIViewController {

override func viewDidLoad() {
let scene = GameScene(size: view.frame.size)
let skView = view as! SKView
skView.presentScene(scene)
}
}

我在这里缺少什么吗?

最佳答案

stickyBlock.anchorPoint = CGPoint(x: xy, y: xy)

关于ios - Spritekit 中的新场景没有显示任何内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52020341/

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