Я хочу, чтобы игра за экраном и игра останавливались, когда экран касался во время конкретной анимации.Когда экран коснулся, как мне закончить игру?
let lightTexture = SKTexture(imageNamed: "green light.png")
let lightTexture2 = SKTexture(imageNamed: "red light.png")
let animateGreenLight = SKAction.sequence([SKAction.waitForDuration(2.0, withRange: 0.1), SKAction.animateWithTextures([lightTexture, lightTexture2], timePerFrame: 3)])
let changeGreenLight = SKAction.repeatActionForever(animateGreenLight)
let animateRedLight = SKAction.sequence([SKAction.waitForDuration(2.0, withRange: 0.1), SKAction.animateWithTextures([lightTexture, lightTexture2], timePerFrame: 3)])
let changeRedLight = SKAction.repeatActionForever(animateRedLight)
let greenLight = SKSpriteNode(texture: lightTexture)
greenLight.position = CGPointMake(CGRectGetMidX(self.frame), 650)
greenLight.runAction(changeGreenLight)
self.addChild(greenLight)
let redLight = SKSpriteNode(texture: lightTexture2)
redLight.position = CGPointMake(CGRectGetMidX(self.frame), 650)
redLight.runAction(changeRedLight)
self.addChild(redLight)
Когда анимация для красного света находится на экране, я хочу, чтобы это была игра. Должен ли я делать оператор if, и если да, то что конкретно?
Спасибо заранее!
вар touchNode = SKSpriteNode() touchNode.size = redLight.size touchNode.position = CGPointMake (CGRectGetMidX (self.frame), 650) пусть AddAction = SKAction.runBlock ({self.addChild (self.touchNode)}) пусть animationAction = SKAction.repeatActionForever (animateRedLight) redLight.runAction (SKAction.sequence ([AddAction, animationAction])) Это то, что Я добавил, когда я пишу self.addChild (touchNode), приложение вылетает. Кроме того, я не думаю, что анимация для touchNode запущена. –
Как сделать так, чтобы при каждом касании экрана игра заканчивалась. –
См. Мой обновленный ответ. –