Jump to content

Save button frame when switching game states?


Phaser911
 Share

Recommended Posts

Hello, I have different states like "menuState", "optionState", "playState".

In optionState I have more than 50 toggle buttons (possible frames: 0 and 1)

So, I can include/exclude different cities by clicking those toggle buttons.

Let's say I click toggle button next to "Berlin", this city is excluded from an array, and button's frame is set to 1 now.

It works fine for all cities, but if I go to menuState or playState, then I go back to optionsState, those toggle buttons are created again, and their frame is 0 by default. Is is possible to save those buttons (keep them on frame 1) after switching the state?

I can add different variables to game.js for example, and when toggle button is clicked, set corresponding variable to 0/1.

But this requires a lot of coding. Is there any better solution?

Thanks

Link to comment
Share on other sites

you can pass the parameter when you call 


this.game.state.start('stateName', true, false, PARAM);

these parameter will be passed to init method of the state you started. 

You can send the current city as a param while you go back to city_selection state. And then in city_selection state you can do changes according to whatever city you get in param.

checkout the docs here.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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