lol lol lol lol - 1 month ago 12
iOS Question

Anyone know the fix to this error regarding an 'override func'?

the error is as specified on the touches began function at the bottom - "override can only be specified on class members". I've tried adding braces, but nothing seems to be working. an answer would be greatly appreciated.

override func didMove(to view: SKView) {
lives = 0
scoreNumber = 0

tapToBegin.text = "Tap To Begin"
tapToBegin.fontSize = 55
tapToBegin.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
tapToBegin.fontColor = UIColor.white
tapToBegin.zPosition = 3
self.addChild(tapToBegin)

FadingAnim = SKAction.sequence([SKAction.fadeIn(withDuration: 0.2), SKAction.fadeOut(withDuration: 0.5)])
tapToBegin.run(SKAction.repeat(FadingAnim, count: 3))

self.backgroundColor = backgroundcolorCustom

let circle = SKSpriteNode(imageNamed: "Circle1")
circle.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
circle.zPosition = 2
circle.name = "circleObject"
self.addChild(circle)

scoreLabel.fontSize = 250
scoreLabel.text = "0"
scoreLabel.fontColor = SKColor.lightGray
scoreLabel.zPosition = 1
scoreLabel.position = CGPoint(x: self.size.width/2, y: self.size.height*0.85)
self.addChild(scoreLabel)

newlifeLabel.fontSize = 125
newlifeLabel.text = "0"
newlifeLabel.fontColor = SKColor.lightGray
newlifeLabel.zPosition = 1
newlifeLabel.position = CGPoint(x: self.size.width/2, y: self.size.height*0.75)
self.addChild(newlifeLabel)

livesLabel.fontSize = 80
livesLabel.text = "0"
livesLabel.fontColor = SKColor.lightGray
livesLabel.zPosition = 1
livesLabel.position = CGPoint(x: self.size.width/3, y: self.size.height*0.83)
self.addChild(livesLabel)

func newLife() {

lives += 1

run(bonusSoundEffect)
let scaleUp = SKAction.scale(by: 1.5, duration: 0.2)
let scaleDown = SKAction.scale(to: 1, duration: 0.2)
let scaleSequence = SKAction.sequence([scaleUp, scaleDown])
livesLabel.run(scaleSequence)

}

func loseLife() {

lives -= 1

let scaleUp = SKAction.scale(by: 1.5, duration: 0.2)
let scaleDown = SKAction.scale(to: 1, duration: 0.2)
let scaleColour = SKAction.colorize(with: UIColor.red, colorBlendFactor: 1, duration: 0.5)
let scaleSequence = SKAction.sequence([scaleUp, scaleDown, scaleColour])
newlifeLabel.run(scaleSequence)

}

func spawnNewCircle() {
var randomImageNumber = arc4random()%4
let circle = SKSpriteNode(imageNamed: "Circle\(randomImageNumber)")
randomImageNumber += 1

circle.zPosition = 2
circle.name = "circleObject"

let randomX = random(min: gameArea.minX + circle.size.width/2,
max: gameArea.maxX - circle.size.width/2)

let randomY = random(min: gameArea.minY + circle.size.height/2,
max: gameArea.maxY - circle.size.height/2)


circle.position = CGPoint(x: randomX, y: randomY)
self.addChild(circle)

circle.run(SKAction.sequence([
SKAction.run(runNormal),
SKAction.run(runGameOver)
]))

circle.run(SKAction.sequence([
SKAction.run(runBonus),
SKAction.run(runGameOver)
]))

}

func runNormal() {

if lives == 0 {
circle.run(SKAction.sequence([
SKAction.scale(by: 0, duration: 2)
]))
}
}

func runBonus() {

if lives >= 1 {
circle.run(SKAction.sequence([
SKAction.scale(by: 0, duration: 5)
]))
}
}

func runGameOver() {

let sceneToMoveTo = GameOverScene(size: self.size)
sceneToMoveTo.scaleMode = self.scaleMode
let sceneTransition = SKTransition.fade(withDuration: 0)
self.view!.presentScene(sceneToMoveTo, transition: sceneTransition)

}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

for touch: AnyObject in touches {

let positionOfTouch = touch.location(in: self)
let tappedNode = atPoint(positionOfTouch)
let nameOfTappedNode = tappedNode.name

if nameOfTappedNode == "circleObject" {

tappedNode.name = ""

tappedNode.removeAllActions()

tappedNode.run(SKAction.sequence([
SKAction.fadeOut(withDuration: 0.3),
SKAction.removeFromParent()
]))

self.run(playPopSoundEffect)

spawnNewCircle()

scoreNumber += 1
scoreLabel.text = "\(scoreNumber)"

newlifescore -= 1
newlifeLabel.text = "\(newlifescore)"

if scoreNumber == 10 || scoreNumber == 50 || scoreNumber == 125 || scoreNumber == 200 || scoreNumber == 300 || scoreNumber == 500 {

spawnNewCircle()

}

if newlifescore == 0 {
newLife()
livesLabel.text = "\(lives)"
newlifescore += 120
}
}
}
}
}


}

Answer

You didn't close didMove() function. Put } before func newLife() {

Comments