Post

Replies

Boosts

Views

Activity

Reply to How to add a .sks file to a playground?
It's possible! I did it in mine. You'll have to add your .sks in the PrivateResourses folder and you'll have to call it in ChaptersChapter1 (or inside the chapter you want)PagesPlaygroundPage1(or inside the page you want)main: swift /*:  Text  Text!  */ //#-hidden-code import PlaygroundSupport import SpriteKit import BookCore // Load the SKScene from 'GameScene.sks' let sceneView = SKView(frame: CGRect(x:0 , y:0, width: 683, height: 1024)) // I called my .sks controller Main1 and the fileNamed is the name of .sks if let scene = Main1(fileNamed: "Main1") {     // Set the scale mode     scene.scaleMode = .aspectFit     // Present the scene     sceneView.presentScene(scene) } PlaygroundSupport.PlaygroundPage.current.liveView = sceneView //#-end-hidden-code Hope it helps!
Apr ’21
Reply to How to transition from a SwiftUI Page to a SpriteKit Scene?
I don't know how you do this for playgrounds, but that's how you integrate spritekit with swiftUI, you use a spriteView: swift // A simple game scene with falling boxes class GameScene: SKScene { override func didMove(to view: SKView) { physicsBody = SKPhysicsBody(edgeLoopFrom: frame) } override func touchesBegan(_ touches: SetUITouch, 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() } } Hope it helps :)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21