Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Kaho Kang
Kaho Kang
12,383 Points

Swift(SpriteKit) initializer errors keeps coming out....

I wrote a Init inside my class, but errors keep appearing in the init, there are three errors:

  1. need a override keyword ;
  2. required initializer must be provided by subclass;
  3. initializer may only declared within a type;

Here is my code:

import SpriteKit

class GameScene: SKScene {

var man:SKSpriteNode
var runningManTextures = [SKTexture]()

override func didMoveToView(view: SKView) {
}


func loadMan() {
    loadManTextures()
    man.position.y -= man.size.height/2
    addChild(man)
}

func loadManTextures() {
    var runningAtlas = SKTextureAtlas(named: "man")
    for i in 1...3 {
        var textureName = "man_\(i)"
        var temp = runningAtlas.textureNamed(textureName)
        runningManTextures.append(temp)
    }
}

init(size:CGSize){

    super.init(size: size)
}


override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    /* Called when a touch begins */

    for touch: AnyObject in touches {
    }
}


override func update(currentTime: CFTimeInterval) {
    /* Called before each frame is rendered */
}

}