Sign in to follow this  

Save button frame when switching game states?

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?


Share this post

Link to post
Share on other sites

you can pass the parameter when you call'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.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.