So im making a game which is pretty much like four squares except you have 20 sprites to place before a square is chosen. I just need help on how to add multiple different sprites by taping the screen 20 times (each time is a different sprite) before executing the square decision. So far the code I have works for just one sprite but then immediately decides which square is chosen. If anyone could help that would be appreciated, thanks!
import SpriteKit
import GameplayKit
class GameScene: SKScene {
var character:SKSpriteNode!
var count:Int = 0
var number:Int!
var countDownLabel:SKLabelNode!
var scoreLabel:SKLabelNode!
var loss:Int = 0
var score:Int = 0 {
didSet {
scoreLabel.text = "Score: \(score)"
}
}
override func didMove(to view: SKView) {
character = SKSpriteNode()
scoreLabel = SKLabelNode(text: "Score: 0")
scoreLabel.position = CGPoint(x: 300, y: 620)
scoreLabel.fontSize = 36
scoreLabel.fontColor = .black
self.addChild(scoreLabel)
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first!
let location = touch.location(in: self)
character = SKSpriteNode(imageNamed: "shuttle")
character.position = location
self.addChild(character)
number = Int(arc4random_uniform(4)+1)
if (location.x < 0 && location.y > 0 && number == 1){
character.removeFromParent()
print("you lose")
loss += 1
} else if (location.x > 0 && location.y > 0 && number == 2){
character.removeFromParent()
print("you lose")
loss += 1
} else if (location.x < 0 && location.y < 0 && number == 3){
character.removeFromParent()
print("you lose")
loss += 1
} else if (location.x > 0 && location.y < 0 && number == 4){
character.removeFromParent()
print("you lose")
loss += 1
} else {
print("you win")
score += 1
}
}