Show the code you use to declare the property for the scene in the SwiftUI view
Here it is:
private var mainCamera: SKCameraNode?
class func newGameScene() -> SKScene {
if let scene = SKScene(fileNamed: "MapScene") {
// Set the scale mode to scale to fit the window
scene.scaleMode = .aspectFill
// Present the scene
return scene
} else {
abort()
}
}
}
What are you trying to do?
I'm trying to access to interact with my scene from a .sks file. By interact, I mean writing code to interact with the scene, like we do when we have a SpriteKit project.
What do you expect to happen?
I can program my scene.
What happens?
I can see my scene in the built project, but I can't program it.
But even if you couldn't help me, at least you tried. So thank you ❤️
Post
Replies
Boosts
Views
Activity
It works with some changes. But I still can't interact with the MapScene because the SpriteView now calls the newGameScene function rather than the MapScene class.
The code I gave you is a little wrong because I wrote it on the go, sorry about that. So, the code from the project:
//imports...
struct MapView: View {
var body: some View {
ZStack {
SpriteView(scene:MapScene())
}
}
}
class MapScene: SKScene {
class func newGameScene() -> MapScene {
guard let scene = SKScene(fileNamed: "MapScene") as? MapScene else {
print("Failed to load GameScene.sks")
abort()
}
scene.scaleMode = .aspectFill
return scene
}
}
Changes applied, but it still shows a black screen.
It works, Thanks!
Oh, Thanks!
This application written on AppleScript using Script Editor
I have a application