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?
Post
Replies
Boosts
Views
Activity
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?
//
// 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( )
}
}
Would it be possible to work with thousands of physical bodies in SpriteKit?