ios - SpriteKit View not presenting Scene in ViewController's viewDidLoad -
goal: red rectangle (of class brick) should appear in blue background node count , fps.
reality: gray background , node count , fps (e.g. no red rectangle or blue background)
i have following code:
gameviewcontroller
import spritekit class gameviewcontroller: uiviewcontroller { override func loadview() { self.view = skview(frame: uiscreen.mainscreen().bounds) } override func viewdidload() { super.viewdidload() let scene: gamescene = gamescene() let viewasskview = self.view as! skview viewasskview.showsfps = true viewasskview.showsnodecount = true viewasskview.backgroundcolor = uicolor.bluecolor() viewasskview.presentscene(scene) } }
my best guess something's wrong gameviewcontroller, i'm not sure what. viewdidload() must've been called because fps , node count.
gamescene
class gamescene: skscene { override func didmovetoview(view: skview) { let mybrick = brick() mybrick.position = cgpointmake(100, 100) self.addchild(mybrick) } }
by lack of complexity, assume nothing wrong gamescene.
appdelegate
import uikit @uiapplicationmain class appdelegate: uiresponder, uiapplicationdelegate { var window: uiwindow? func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]?) -> bool { self.window = uiwindow(frame: uiscreen.mainscreen().bounds) self.window!.backgroundcolor = uicolor.orangecolor() self.window!.rootviewcontroller = gameviewcontroller() self.window!.makekeyandvisible() return true }
i know nothing wrong appdelegate, because if changed self.window!.rootviewcontroller uiviewcontroller, orange screen.
your scene has no size. can set size programmatically initializing scene using size initializer.
let scene: gamescene = gamescene(size:view.bounds.size)
or set scene's scale mode resizefill
size of scene resize match skview's size:
scene.scalemode = skscenescalemode.resizefill
additionally may want view answer here learn more sprite kit scaling.
Comments
Post a Comment