I got my game where I have four lanes going upwards from the bottom of my screen to the top, obviously. I got a object which is the right one showing on my scene and I spawn random objects in a spawn wave, 1 for each lane, so 4 at a time, and I want to check that at least one of the 4 objects is the right object, if not, delete and spawn new 4 objects until you got one right.
Cause now sometimes you have to wait like 10-20 seconds until a right object appears which really transpired that it is boring and takes you out of the game flow.
Following code spawns the helmets:
private func spawnRandomHelmet(){
let helmet = HelmetNode(fruit: .random())
helmet.delegate = self
helmet.position = CGPoint(x: 0, y: 0 - helmet.size.height)
addChild(helmet)
let endOfFieldForHelmet = self.size.height * 0.7864 - (helmet.size.height - screenWidth / 7.5)
let helmetOutOfScreen = self.size.height + helmet.size.height
let moveHelmetUp = SKAction.moveTo(y: endOfFieldForHelmet, duration: self.config.helmetSpeed)
helmet.run(moveHelmetUp) {
let moveHelmetOutOfScreen = SKAction.moveTo(y: helmetOutOfScreen, duration: 0.5)
let fadeOutHelmet = SKAction.fadeOut(withDuration: 0.5)
let moveAndFadeOut = SKAction.group([moveHelmetOutOfScreen, fadeOutHelmet])
helmet.run(moveAndFadeOut) {
helmet.removeFromParent()
self.delegate?.removed(helmet.fruit)
}
}
}
Aucun commentaire:
Enregistrer un commentaire