ios - Segue between scenes without initializing scene -


i new swift , having immense trouble multi-scene spritekit situation.

let me give background:

my game attempting have 3 screens; intro, upgrade scene, , play scene. intro scene either initializes upgrade scene or initialized play scene per users touch (there 2 buttons on intro screen, choose either play or go upgrade scene). upgrade screen can press variety of buttons change variables effecting sprites speed, texture, , variety of other stuff. when finished there button user can press initialize play scene. when sprite touches node in play scene, intro screen initializes again.

the tricky part have been working on trying upgrade screen have effect on play screen without declaring of variables global (this worked first play, upon trying press on screen again got massive amount of exc , sigabrt errors, bad memory access).

for example:

upgradescene:

class upgradescene: skscene, skphysicscontactdelegate {      var groundspeed = 5.0     var hero = skspritenode(imagenamed:"hero")      override func touchesbegan(touches: nsset, withevent event: uievent){          touch: anyobject in touches{              let location = touch.locationinnode(self)              if self.nodeatpoint(location) == self.sbutton1 {                 groundspeed = 25.0             }              if self.nodeatpoint(location) == self.sbutton2 {                 hero.texture = sktexture(imagenamed:"hero2")             }              if self.nodeatpoint(location) == self.playscenebutton {                 var scene = playscene(size:self.size)                 let skview = self.view! skview                 scene.scalemode = .resizefill                 scene.size = skview.bounds.size                 skview.presentscene(scene)             }         } } 

so hope when press third button, changes brought first 2 buttons function in functions carry in next scene:

playscene:

class playscene: upgradescene{      override func update(currenttime: nstimeinterval) {          runningbar.position.x -= cgfloat(groundspeed)          //so groundspeed change other scene work here...         //but initializes original declared values     } } 

the playscene inheriting upgradescene , run groundspeed original values, doesn't recognize change made button press.

question

how can upgrade scene effect play scene without causing bunch of memory errors? can open differently instead of initializing , losing changes made in upgrade scene original variable values, textures etc...?

my advice not make playscene inherit upgradescene, if intention use updated values. in fact, discovered yourself, changes don't show in playscene.

you're misinterpreting idea of inheritance. comment //but initializes original declared values expect. can't inherit changes. inheritance doesn't work that.

you're correct in avoiding global variables.

what might want set class holds , manages changes. i'd advise use nsuserdefaults track changes, , use class interpret changes.

for example, racing game might let customize engine different speeds. store speed integer , option pick in customization screen, update value in nsuserdefaults. when time comes player play game, i'll have class interprets number stored in nsuserdefaults , gives car appropriate speed.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -