Hello everyone, does anyone know how to fix this problem? When I run iPhone simulator, physics for sprites and touches doesn't work, however on real device everything is fine.
Also the error still appears: Immutable value 'touch' was never used; consider replacing with '_' or removing it
import SpriteKit
class GameScene: SKScene, SKPhysicsContactDelegate {
var knife = SKSpriteNode(imageNamed: "knife")
var target = SKSpriteNode(imageNamed: "target")
override func didMove(to view: SKView) {
physicsBody = SKPhysicsBody(edgeLoopFrom: frame)
physicsWorld.contactDelegate = self
spawnKnife()
spawnTarget()
}
func spawnKnife() {
knife.texture?.filteringMode = .nearest
knife.size = CGSize(width: 256, height: 256)
knife.position = CGPoint(x: 0, y: UIScreen.main.bounds.minY - 300)
knife.physicsBody = SKPhysicsBody(texture: knife.texture!, size: knife.size)
knife.physicsBody?.isDynamic = true
addChild(knife)
}
func spawnTarget() {
target.texture?.filteringMode = .nearest
target.size = CGSize(width: 512, height: 256)
target.position = CGPoint(x: 0, y: UIScreen.main.bounds.maxY - 128)
target.physicsBody = SKPhysicsBody(texture: target.texture!, size: target.size)
target.physicsBody?.isDynamic = false
addChild(target)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
knife.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 1000))
}
}
Post
Replies
Boosts
Views
Activity
Hello! Help please, after updating the system to Big Sur, my MacBook Pro 13 began to slow down, previously there were no such problems.
MacBook Pro (Retina, 13-inch, Early 2015)
2,7 GHz 2‑core processor Intel Core i5
8 GB 1867 MHz DDR3
Intel Iris Graphics 6100 1536 MB