Post

Replies

Boosts

Views

Activity

Reply to Swarm simulation
import SwiftUI import SpriteKit struct ContentView: View {     var scene: SKScene {         let scene = GameScene()         scene.size = CGSize(width: 400, height: 700)         scene.scaleMode = .fill         return scene     }          var body: some View {         SpriteView(scene: scene)             .frame(width: 400,height: 700)             .ignoresSafeArea()     } } class GameScene: SKScene{     var boxes: [SKShapeNode] = []     var lastUpdateTime: TimeInterval?          override func didMove(to view: SKView) {         view.preferredFramesPerSecond = 60         physicsBody = SKPhysicsBody(edgeLoopFrom: frame)     }          override func touchesBegan(_ touches: Set, with event: UIEvent?) {         guard let touches = touches.first else {return}         let location = touches.location(in: self)         let box = SKShapeNode(circleOfRadius: 5)         box.fillColor = .brown         box.position = location         box.physicsBody = SKPhysicsBody(circleOfRadius: 10)         box.physicsBody?.affectedByGravity = false         let magneticField = SKFieldNode.radialGravityField()         magneticField.strength = 1000         magneticField.falloff = 1.0         magneticField.region = SKRegion(radius: 10)         magneticField.physicsBody = box.physicsBody         magneticField.position = box.position         addChild(box)         boxes.append(box)     }          override func update(_ currentTime: TimeInterval) {         // Calculate time since last update         let deltaTime = currentTime - (lastUpdateTime ?? currentTime)                  // Update game state based on time since last update         updateGameState(deltaTime: deltaTime)                  // Store the current time as the last update time         lastUpdateTime = currentTime     }     private func updateGameState(deltaTime: TimeInterval) {         // Update game state based on time since last update         for box in boxes {             let dx = CGFloat.random(in: -50...50)             let dy = CGFloat.random(in: -50...50)             let randomMovement = SKAction.move(by: CGVector(dx: dx, dy: dy), duration: 1.0)                          // Check if box is beyond screen edges             let screenBounds = UIScreen.main.bounds             let minX = screenBounds.minX + box.frame.width/2             let maxX = screenBounds.maxX - box.frame.width/2             let minY = screenBounds.minY + box.frame.height/2             let maxY = screenBounds.maxY - box.frame.height/2             box.run(randomMovement)             if box.position.x < minX  {                     box.position.x = minX                              }else if box.position.x > maxX - 35 {                     box.position.x = maxX - 35                              } else if box.position.y < minY + 10 {                     box.position.y = minY + 10                              }else if box.position.y > maxY - 240 {                     box.position.y = maxY - 240                              }         }     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’23
Reply to Swarm simulation
You would use SpriteKit for that. I'm new to it too, but I used a magnetic field around randomly moving objects to create something similar to a swarm. First of all random movement was quite a challenge. I haven't figured it out completely yet, but the movement now at least seems to be random.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’23
Reply to TextEditor Problem Or Me?
clean your build folder it shouldn't do that. The assertion error doesn't have to do anything with the crash.
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Sep ’25
Reply to It says: "There are still screenshot uploads in progress." when submit a new build
Hi I solved the issue with my App. Some bug caused that for me there have been two 6.5" sections for upload, so I deleted all screenshots from the duplicate one and moved them to the section that had the "required" label. And that solved it for me.
Replies
Boosts
Views
Activity
May ’24
Reply to Swarm simulation
import SwiftUI import SpriteKit struct ContentView: View {     var scene: SKScene {         let scene = GameScene()         scene.size = CGSize(width: 400, height: 700)         scene.scaleMode = .fill         return scene     }          var body: some View {         SpriteView(scene: scene)             .frame(width: 400,height: 700)             .ignoresSafeArea()     } } class GameScene: SKScene{     var boxes: [SKShapeNode] = []     var lastUpdateTime: TimeInterval?          override func didMove(to view: SKView) {         view.preferredFramesPerSecond = 60         physicsBody = SKPhysicsBody(edgeLoopFrom: frame)     }          override func touchesBegan(_ touches: Set, with event: UIEvent?) {         guard let touches = touches.first else {return}         let location = touches.location(in: self)         let box = SKShapeNode(circleOfRadius: 5)         box.fillColor = .brown         box.position = location         box.physicsBody = SKPhysicsBody(circleOfRadius: 10)         box.physicsBody?.affectedByGravity = false         let magneticField = SKFieldNode.radialGravityField()         magneticField.strength = 1000         magneticField.falloff = 1.0         magneticField.region = SKRegion(radius: 10)         magneticField.physicsBody = box.physicsBody         magneticField.position = box.position         addChild(box)         boxes.append(box)     }          override func update(_ currentTime: TimeInterval) {         // Calculate time since last update         let deltaTime = currentTime - (lastUpdateTime ?? currentTime)                  // Update game state based on time since last update         updateGameState(deltaTime: deltaTime)                  // Store the current time as the last update time         lastUpdateTime = currentTime     }     private func updateGameState(deltaTime: TimeInterval) {         // Update game state based on time since last update         for box in boxes {             let dx = CGFloat.random(in: -50...50)             let dy = CGFloat.random(in: -50...50)             let randomMovement = SKAction.move(by: CGVector(dx: dx, dy: dy), duration: 1.0)                          // Check if box is beyond screen edges             let screenBounds = UIScreen.main.bounds             let minX = screenBounds.minX + box.frame.width/2             let maxX = screenBounds.maxX - box.frame.width/2             let minY = screenBounds.minY + box.frame.height/2             let maxY = screenBounds.maxY - box.frame.height/2             box.run(randomMovement)             if box.position.x < minX  {                     box.position.x = minX                              }else if box.position.x > maxX - 35 {                     box.position.x = maxX - 35                              } else if box.position.y < minY + 10 {                     box.position.y = minY + 10                              }else if box.position.y > maxY - 240 {                     box.position.y = maxY - 240                              }         }     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Mar ’23
Reply to Swarm simulation
You would use SpriteKit for that. I'm new to it too, but I used a magnetic field around randomly moving objects to create something similar to a swarm. First of all random movement was quite a challenge. I haven't figured it out completely yet, but the movement now at least seems to be random.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’23