为什么 Xcode 不显示模拟器运行超时的节点?

发布于 2025-01-18 15:57:52 字数 1348 浏览 1 评论 0原文

我的GameScene Swift文件中有此代码:

var background = SKSpriteNode(imageNamed: "background")
let blockImage = SKTexture(imageNamed: "block")
let blockSize = CGSize(width: 64, height: 64)
override func didMove(to view: SKView) {
    setUpGame()
}
func setUpGame(){
    background.position = CGPoint(x: frame.size.width / 2, y: frame.size.height / 2)
    addChild(background)

    let block = SKSpriteNode(texture: blockImage, size: blockSize)
    block.position.x = block.frame.width/2
    block.position.y = frame.height - block.frame.height/2
addChild(block)
}

这是我的GameController文件中的代码:

override func viewDidLoad() {
    super.viewDidLoad()
    
    if let view = self.view as! SKView? {
        // Load the SKScene from 'GameScene.sks'
        let scene = GameScene(size: self.view.bounds.size)
            // Set the scale mode to scale to fit the window
            scene.scaleMode = .aspectFill
            
            // Present the scene
            view.presentScene(scene)
    
        
        view.ignoresSiblingOrder = true
        
        view.showsFPS = true
        view.showsNodeCount = true
        
        // added to see physics body
        view.showsPhysics =  true
    }
}

为什么除了背景外,我的块节点在模拟器上出现多个运行?块最终显示后,每次运行后将继续显示,直到我编辑代码。香港专业教育学院尝试删除我的背景节点,以防万一可能是问题,但没有改变任何东西

I have this code in my GameScene swift file:

var background = SKSpriteNode(imageNamed: "background")
let blockImage = SKTexture(imageNamed: "block")
let blockSize = CGSize(width: 64, height: 64)
override func didMove(to view: SKView) {
    setUpGame()
}
func setUpGame(){
    background.position = CGPoint(x: frame.size.width / 2, y: frame.size.height / 2)
    addChild(background)

    let block = SKSpriteNode(texture: blockImage, size: blockSize)
    block.position.x = block.frame.width/2
    block.position.y = frame.height - block.frame.height/2
addChild(block)
}

This is my code in my GameController file:

override func viewDidLoad() {
    super.viewDidLoad()
    
    if let view = self.view as! SKView? {
        // Load the SKScene from 'GameScene.sks'
        let scene = GameScene(size: self.view.bounds.size)
            // Set the scale mode to scale to fit the window
            scene.scaleMode = .aspectFill
            
            // Present the scene
            view.presentScene(scene)
    
        
        view.ignoresSiblingOrder = true
        
        view.showsFPS = true
        view.showsNodeCount = true
        
        // added to see physics body
        view.showsPhysics =  true
    }
}

why does it take multiple runs for my block node to appear on the simulator except for my background? After the block finally show, it will continue to show after every run until I edit my code. Ive tried removing my background node just in case that might be the issue, but it didn't change anything

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文