Post

Replies

Boosts

Views

Activity

Here is a simplistic SpriteKit example. Anybody knows why I can't reset the scene by removing all children with tap of a button from SwiftUI?
// // ContentView.swift // TestSprite1 // // Created by Alireza | Datance on 4/14/22. // import SwiftUI import SpriteKit class GameScene: SKScene {   override func didMove(to view: SKView) {     physicsBody = SKPhysicsBody(edgeLoopFrom: frame)   }   override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {      //with this we would only process single touch     // good question how to process multi touch      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)                 } } struct ContentView: View {   var scene: SKScene {     let scene = GameScene()     scene.size = CGSize(width: 300, height: 400)     scene.scaleMode = .fill     return scene      }       func initScene () {     // why doesn't it work     scene.removeAllActions()     scene.removeAllChildren()         }       var body: some View {     VStack {       Text("Hello, world!")         .padding()       Button("Reset") {         initScene()       }               SpriteView(scene: scene)         .frame(width: 300, height: 400)         .ignoresSafeArea()     }         } } struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView( )   } }
0
0
576
Apr ’22
.navigationTitle behaves differently on macOS and iOS. Any reference to this?
I noticed that .navigationTitle() behaves differently in iOS and macOS. But couldn't find a reference to this anywhere. On iOS I have to put it on the NavigationViews content but on macOS I have to put it directly on NavigationView for it to show up. I suppose I can make the code platform dependent but it is rather ugly. Am I doing something wrong? Has anyone else come across this?
0
0
485
Apr ’22