Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make SpriteView display physics or node count

When I try to set the showPhysics property to true in the didMove(to:) function of my Scene it doesn't do anything when I present it using a SpriteView in SwiftUI. The same thing happens when I try to show the FPS and node count. Here is the code:

class GameScene: SKScene {
    override func didMove(to view: SKView) {
        view.showsFPS = true
        size = view.frame.size
        
        addChild(SKSpriteNode(color: .yellow, size: CGSizeMake(50, 50)))
    }
}

struct ContentView: View {
    var body: some View {
        VStack {
            Text("My Game")
            SpriteView(scene: GameScene())
        }
        .padding()
    }
}

Is this a bug or am I using SpriteView wrong?

like image 454
rayaantaneja Avatar asked Nov 17 '25 11:11

rayaantaneja


1 Answers

You'll want to set these using the SpriteView.DebugOptions when you create your SpriteView.

For example:

struct ContentView: View {
    var body: some View {
        VStack {
            Text("My Game")
            SpriteView(scene: GameScene(), debugOptions: [.showsFPS, .showsNodeCount, .showsPhysics])
        }
        .padding()
    }
}
like image 95
Calin Avatar answered Nov 20 '25 02:11

Calin