swift - Game Scene cannot be constructed because it has not accessible initializers -


xcode dropping error , dont know how solve it. maybe can give me hand or hint?

here code working within game scene:

var currentlevel: int = 1  var platforms: platformsnode! var platformnode1: platformnode! var platformnode2: platformnode! var platformnode3: platformnode!  var platformarray = [sknode]()  let passenger = skspritenode(imagenamed: "passenger")  var passengernumber:int = 1 var startplatform =         [3, 3, 2, 1, 2] var destinationplatform =   [1, 1, 3, 2, 1]  // level selection class func level(levelnum: int) -> gamescene? {     let scene = gamescene(filenamed: "level\(levelnum)")! // <- compiler error     scene.currentlevel = levelnum     scene.scalemode = .aspectfill     return scene } 

as want replace let passenger = skspritenode(imagenamed: "passenger") let passenger: passengernode! compiler drops compiler error "game scene cannot constructed because has not accessible initializers". , error shows up, when change way want declare let passenger. reason want change it, want replace class, passenger a. can have different type different texture (this can may solved differently) b. can removed parent , later added again - no error.

you got ideas? stuck somehow :-?

declaring passenger type , no initial value requires add init() class because compiler not know initial value give when object created.

you can either create init() , set value passenger or delare

let passenger: passengernode! = nil 

(this assumes code not reference variable before making sure put in or checks nil/optional before using it).


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -