ios - swift2 how can an object of SKScene class takes a size as a parameter? -


i following tutorial

this code

class gamescene: skscene {      override func didmovetoview(view: skview) {      }     override func touchesbegan(touches: set<uitouch>, withevent event: uievent?) {      }     override func update(currenttime: nstimeinterval) {      }  } 

as see there no init method. though when in view controller:

//create , configure scene     scene = gamescene(size : skview.bounds.size) 

where scene is:

 var scene: gamescene! 

it works. how can gamescene approves have init size though didn't code that?

any additial information sksprite appreciated. new framework

your gamescene subclass of skscene, inherit init size initializer skscene.

if command-click on skscene in code, bring header information class:

public class skscene : skeffectnode {      /**      called once when scene created, one-time setup here.       scene infinitely large, has viewport frame through present content of scene.      passed in size defines size of viewport use present scene.      display different portions of scene, move contents relative viewport. 1 way create sknode function viewport transformation. node should have visible conents parented under it.       @param size size in points signifies viewport scene defines framing of scene.      */     public init(size: cgsize) 

another helpful technique in xcode option-clicking on function calls find out defined. unfortunately, doesn't work initializers unless explicitly call them in code. workaround change:

var scene = gamescene(size : skview.bounds.size) 

to

var scene = gamescene.init(size : skview.bounds.size) 

and option-click on init brings following:


skscene initializer

you can click on skscene class reference more information.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -