Search the Community
Showing results for tags 'preserving objects'.
-
Hello, in my game I will be very often switching states - for example Intro and Office. In each state user can kill some objects, which were created in init function when the state was started for the first time. Lets assume that in the Office state user killed two objects, then he goes to Intro state and then back to Office - is there some way to preserve that state as it was before the state change? Without holding some global array with informations about all objects if they were killed or not? My sample code: intro.js MyGame.intro = function (game) { this.background; this.character;};MyGame.intro.prototype = { create: function () { this.background = this.add.sprite(0, 0, 'loadingBackground'); this.character = game.add.sprite(game.world.centerX, game.world.centerY, 'aml_1', 'aml_avatar_hindus.jpg'); var left = game.add.sprite(game.world.centerX-232, game.world.centerY - 200, 'aml_1', 'strzalka_lewo.png'); var right = game.add.sprite(game.world.centerX+200, game.world.centerY - 200, 'aml_1', 'strzalka_prawo.png'); this.character.anchor.setTo(0.5,0.5); var startBtn = game.add.sprite(game.world.centerX, game.world.centerY+300, 'aml_1', 'letsstart.png'); startBtn.anchor.set(0.5); startBtn.inputEnabled = true; startBtn.events.onInputDown.add(this.startClicked, this); game.scale.pageAlignHorizontally = true; game.scale.pageAlignVertically = true; // using RESIZE scale mode game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; game.scale.setScreenSize(true); }, startClicked: function () { this.state.start('Office', false, false); } };office.js MyGame.office = function (game) { this.background; this.character; this.sheet; this.btn; this.zszywacz;};MyGame.office.prototype = { init: function () { this.background = this.add.sprite(0, 0, 'officeBackground'); this.sheet = this.add.sprite(game.world.centerX, game.world.centerY, 'aml_1', 'pole.png'); this.sheet.anchor.set(0.5); this.btn = this.add.sprite(game.world.centerX, game.world.centerY + 300, 'aml_1', 'play.png'); this.btn.anchor.set(0.5); this.btn.inputEnabled = true; this.btn.events.onInputDown.add(this.btnClicked, this); this.spawnHiddenObjects(); }, create: function() { }, btnClicked: function() { this.sheet.kill(); this.btn.kill(); console.log(this.sheet); }, spawnHiddenObjects: function() { this.zszywacz = this.add.sprite(1302, 587, 'aml_1', 'zszywacz.png'); this.zszywacz.inputEnabled = true; this.zszywacz.events.onInputDown.add(this.zszywaczClicked, this); }, zszywaczClicked: function() { this.state.start('Intro', false, false); } };Any help would be appreciated, thanks.
- 5 replies
-
- states
- states switching
-
(and 4 more)
Tagged with: