Search the Community
Showing results for tags 'statemanager'.
-
So I want to make states which can have custom constructor parameters of some sorts. This is my testState: export class TestingState extends Phaser.State { constructor(firstVar: any, secondVar: any, thirdVar: any) { console.log(firstVar); console.log(secondVar); console.log(thirdVar); super(); } } The firstVar is always the Phaser.Game variable, but the second and third are supposed to be custom parameters. I start my state like this: this.game.state.add('testState', GameStates.TestingState, false); this.game.state.start('testState', false, false, 'Hello', 'test'); The firstVar just logs the Phaser.Game and the second and third print out undefined. But if I remove the 'test' argument, it doesn't log anything the third time.
-
In Interphase #1, the 19 properties of Phaser.State are listed, but there are only 18 referenced in the documentation. The state property (which reference to the game StateManager) is not declared in the Phaser.State constructor but still linked by the StateManager. Shouldn't it be added alongside the 18 others properties in the Phaser.State constructor, so it show up as well in the documentation?
-
I am seeing strange behavior trying to switch states. I have a state called Game in a file called game.js. This state loads and runs correctly. It is preceded by a boot state and a preload state. Switching from Boot to Preload to Game works fine. Once I user does something, I call game.state.start("MainUI"); within the Game states update function. The MainUI state starts, the preload function executes correctly, the create function executes correctly. The shutdown function in the Game state also works correctly. However, after completing the create function in "MainUI" it does not move on to the update function, it jumps back to the create function of the "Game" state. So it never really switches to the new state, it starts to, runs the preload and create from the new state, and then current state gets back to Game and it runs the Game state from the beginning in its entirety. I have no idea why this is happening. Any thoughts would be appreciated. What can cause a simple state switch to not complete and jump back to the calling state? Thanks. Some code below. Setup: var game = new Phaser.Game(1920, 1080, Phaser.CANVAS, 'game_div');game.state.add('Boot', Boot);game.state.add('Preload', Preload);game.state.add('Game', Game);game.state.add('MainUI', MainUI);game.state.start('Boot');Call in game.js: game.state.start("MainUI");Everything works up to that point, MainUI loads and runs its preload followed by create. MainUI is currently very simple, I am just trying to get the state transition working. It never gets to console_in or update. It immediate switches state back to Game and runs it from its top after completing the MainUI create function. define([ 'phaser'], function (Phaser) {'use strict'; function MainUI(game) {gameC = game; console.log('MainUI Constructor'); }var gameC;var consoleSnakes;var consoleGroup;var console_tween;var kbBase, kbPlate, dispBase, facePlate;var loaded_flag;MainUI.prototype = { constructor: MainUI, start: function(game) { }, preload: function(){ loaded_flag = 0; consoleGroup = this.add.group(); consoleSnakes = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY, 'loading_snakes', 5); consoleSnakes.scale.set(1); consoleSnakes.smoothed = false; consoleSnakes.anchor.setTo(0.5, 0.5); consoleSnakes.alpha = 1; var anim = consoleSnakes.animations.add('slither'); anim.play(10, true); anim.setFrame(this.game.snakes_frame, true); this.game.load.image('console_base', 'assets/console/MainUI_Base.png'); this.game.load.image('console_display', 'assets/console/MainUI_Display.png'); this.game.load.image('console_faceplate', 'assets/console/MainUI_Faceplate.png'); this.game.load.image('console_keyplate', 'assets/console/MainUI_KeyboardPlate.png'); this.game.load.image('console_energy_disc', 'assets/console/MainUI_EnergyDisc.png'); this.game.load.image('console_energy_shutter', 'assets/console/MainUI_EnergyShutter.png'); this.game.load.image('console_energy_shadow', 'assets/console/MainUI_EnergyShadow.png'); console.log("preloaded"); }, create: function(){ kbBase = consoleGroup.create(this.game.world.centerX, this.game.world.centerY, 'console_base'); kbBase.anchor.setTo(0.5, 0.5); //keys, key selection button, lights kbPlate = consoleGroup.create(this.game.world.centerX, this.game.world.centerY, 'console_keyplate'); kbPlate.anchor.setTo(0.5, 0.5); dispBase = consoleGroup.create(this.game.world.centerX, this.game.world.centerY, 'console_display'); dispBase.anchor.setTo(0.5, 0.5); //energy disc, shutter, shadow //display components facePlate = consoleGroup.create(this.game.world.centerX, this.game.world.centerY, 'console_faceplate'); facePlate.anchor.setTo(0.5, 0.5); //buttons consoleGroup.alpha = 1; this.game.add.tween(consoleSnakes).to( { alpha: 0 }, 750, Phaser.Easing.Exponential.Out, true, 10); console_tween = this.game.add.tween(consoleGroup).to( { alpha: 1 }, 1000, Phaser.Easing.Exponential.In, true); console_tween.onComplete.add(MainUI.prototype.console_in, this); console.log("created"); }, console_in: function() { loaded_flag = 1; console.log("console_in"); }, update: function() { if(loaded_flag == 1) { console.log("loaded"); loaded_flag = 2; } }, shutdown: function() { } }; return MainUI;});
-
Having read through the excellent StateManager guide in the first issue of Interphase magazine I was left with a few questions in my head. It's suggested a whole state might be used to represent an in-game weapon/item shop. If this was done is there a way to have one state open up on top of the previous running state to maintain the background in some way? Just thinking that weapon shops often open as an overlay on a game (can't think of examples in my head of hand right now) If not - is grabbing the canvas buffer before switch states a better way to use as a background for the new state ?