SwiftUI + SpriteView = Gray screen

Xcode 13 beta 2, iOS 15 beta 2, the following code produces a gray screen (the SKScene GameScene.didMove(to:) never gets called):

import SwiftUI
import SpriteKit

// A simple game scene with falling boxes
class GameScene: SKScene {
    override func didMove(to view: SKView) {
        physicsBody = SKPhysicsBody(edgeLoopFrom: frame)
    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        guard let touch = touches.first else { return }
        let location = touch.location(in: self)
        let box = SKSpriteNode(color: SKColor.red, size: CGSize(width: 50, height: 50))
        box.position = location
        box.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: 50, height: 50))
        addChild(box)
    }
}

// A sample SwiftUI creating a GameScene and sizing it at 300x400 points
struct ContentView: View {
    var scene: SKScene {
        let scene = GameScene()
        scene.size = CGSize(width: 300, height: 400)
        scene.scaleMode = .fill
        return scene
    }

    var body: some View {
        SpriteView(scene: scene)
            .frame(width: 300, height: 400)
            .ignoresSafeArea()
    }
}

I have no idea how to fix / workaround this issue.

Any thoughts?

  • I'm running into the same issue. Out of curiosity, I decided to run the project with My Mac (Designed for iPad) as the target simulator device, and it works perfectly fine there. I am going to try running it on my iPad and see if that does anything different.

Add a Comment

Accepted Reply

iOS 15 beta 5 has fixed this issue!

Add a Comment

Replies

My SpriteViews that worked well with iOS 14 just stopped rendering anything else than a background with iOS 15, both on iOS and catalyst. Reported since b1, including example project, still not working at all in b3.

I am having the exact same problem. I tried in a playground with a really simple scene (adding a yellow circle). It works if I display the view directly but SpriteView() in a swiftUI struct results in a blank gray screen.

  • This is still an issue with Xcode 13 beta 3 with Simulator running iOS 15 beta 3.

    If I run my SpriteView() code on the Simulator with iOS 14.5 it works fine. Hopefully this will be fixed in iOS 15 beta 4!

Add a Comment

Still an issue in Xcode 13 beta 4. :-/

  • Confirmed still no progress since beta1

Add a Comment

Has anyone written a feedback for this? It seems like a common issue.

Yes, I wrote a Feedback with a sample project for beta1 - FB9197892. No response as of right now.

iOS 15 beta 5 has fixed this issue!

Add a Comment