Jump to content

Help with state change and importing sprites from states


Domdom15
 Share

Recommended Posts

Hi, 

I am new to game development and am trying to make a game where one stage has 6 characters and user can choose any number of characters from here and only those characters will be loaded in next stage. I am using different js files for each stage. Please help. 

Thanks in advance 

Link to comment
Share on other sites

When the player picks a character, where are you storing what they've picked? Since you're already storing that somewhere, you need to make that available to another state, right? There's a couple of choices.

1. You can store it in a global variable or as part of a global variable. Like if your game is called "Adventure!" you could make a variable called "window.adventure = {};". It's now globally accessible across all files. You could then stick an array on this global var and read it anywhere: "window.adventure.playerPicks = [1,2,3,5];"

2. You're already storing the choice in one state and want to pass it to a second state. When you call "this.start('nameOfNextState');" you can pass extra parameters like this: "this.start('stateName', clearWorld, clearCache, arg1, arg2, arg3);" The "clearWorld" and "clearCache" params are for Phaser. "clearWorld" defaults to true and "clearCache" defaults to false, so you could pass true and false there. Then you could pass whatever you want. In your next state, make a method called "init". "init" will receive those params as its arguments: "init: function(arg1, arg2, arg3) {}". The docs might explain it better than I can: http://phaser.io/docs/2.6.2/Phaser.StateManager.html#start

Honestly, I use the first option. There's lots of global state that lots of places in my game need access to.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...