ios - How to change the background color with Sprite Kit -


i'm trying make game sprite kit in swift have little problem background color.

i started new project on xcode , selected "game" presets , sprite kit. have starter project grey background "hello world" in white , spaceships appear when press on screen.

so removed code don't care when launch game, still have grey background, if try change in gamescene.swift file.

here files:

appdelegate.swift

import uikit  @uiapplicationmain class appdelegate: uiresponder, uiapplicationdelegate {  var window: uiwindow?   func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]?) -> bool {     // override point customization after application launch.     return true   }  func applicationwillresignactive(application: uiapplication) {     // sent when application move active inactive state. can occur types of temporary interruptions (such incoming phone call or sms message) or when user quits application , begins transition background state.     // use method pause ongoing tasks, disable timers, , throttle down opengl es frame rates. games should use method pause game.   }  func applicationdidenterbackground(application: uiapplication) {     // use method release shared resources, save user data, invalidate timers, , store enough application state information restore application current state in case terminated later.     // if application supports background execution, method called instead of applicationwillterminate: when user quits.   }  func applicationwillenterforeground(application: uiapplication) {     // called part of transition background active state; here can undo many of changes made on entering background.   }  func applicationdidbecomeactive(application: uiapplication) {     // restart tasks paused (or not yet started) while application inactive. if application in background, optionally refresh user interface.   }  func applicationwillterminate(application: uiapplication) {     // called when application terminate. save data if appropriate. see applicationdidenterbackground:.   }  } 

gamescene.swift

import spritekit  class gamescene: skscene {   override func didmovetoview(view: skview)   {     self.backgroundcolor = skcolor.whitecolor()   }    override func update(currenttime: cftimeinterval)   {     /* called before each frame rendered */   } } 

gameviwcontroller.swift

import uikit import spritekit   class gameviewcontroller: uiviewcontroller {    override func viewdidload()   {     super.viewdidload()   }    override func prefersstatusbarhidden() -> bool   {     return true   } } 

so how set background in white?

it not change because trying change background color if gamescene not loaded gameviewcontroller because remove code.

so add code in gameviewcontroller.swift:

override func viewdidload() {     super.viewdidload()      // load gamescene     let scene = gamescene(size: view.bounds.size)     let skview = view as! skview     skview.showsfps = false     skview.showsnodecount = false     skview.ignoressiblingorder = true     scene.scalemode = .resizefill     skview.presentscene(scene) } 

after work fine.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -