I'm trying to do something that seems straightforward, but I'm getting "use of unresolved identifier" instead of the variable I'm expecting.
In one class I'm instantiating an object:
let sprite = Hero(view: view)
View is a valid variable, and I can po it in this class.
In Hero, I have my init function setup as follows:
init(view: SKView) {
...
}
But when I try to po view from this initializer, I get the "use of unresolved identifier" error. Any idea why?
EDIT:
Here's all my relevant code:
GameScene.swift
import SpriteKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
let sprite = Hero(view: view)
self.addChild(sprite)
}
}
Hero.swift
import SpriteKit
class Hero: SKSpriteNode {
init(view: SKView) {
let texture = SKTexture(imageNamed:"Spaceship")
let color = SKColor(white: 0, alpha: 0)
let size = CGSizeMake(100, 100)
super.init(texture:texture, color:color, size:size)
self.xScale = 1.0
self.yScale = 1.0
self.position = CGPointMake((view.bounds.width / 2) - (size.width / 2), view.bounds.height - 200)
}
}
Everything about this code works, the spaceship will show up if I set the position to, let's say CGPointMake(200,200), only view is unresolved in Hero. I'm passing view so that Hero knows the bounds of the view it's being added to and can center itself.
let sprite = Hero( view)?