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
636
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
557
Apr ’22
Swarm simulation
I'm new to iOS. What would be the right toolkit to create something like a swarm animation with thousands of objects on the screen moving at high speed?
Replies
2
Boosts
1
Views
1.8k
Activity
Mar ’23
SpriteKit Performance
Would it be possible to work with thousands of physical bodies in SpriteKit?
Replies
2
Boosts
0
Views
1.2k
Activity
Apr ’22
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( )   } }
Replies
0
Boosts
0
Views
636
Activity
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?
Replies
0
Boosts
0
Views
557
Activity
Apr ’22