How do I temporarily stop an actor from registering touches?
Quick background info
I want to avoid having 2 scenes in my menu, so I created a game attribute which dictates what "state" the scene is in. 0 for "Main Menu" state, 1 for "Settings" state.
If this attribute is 0, then the buttons in the Main Menu are usable. If this attribute is 1, then the Main Menu buttons are NOT usable and an overlay is placed on top of the scene with the items from the Settings menu.
Important to know: My Main Menu buttons take you to levels when touch is "released".
On to the issue
Let's say that you are in the Settings state. You do your thing, and touch on the spot where in the below layer is a "Main Menu" state button (let's say the "achievements" button). That button will not trigger, since the Main Menu buttons are disabled because you are in Settings state. All good and dandy until you hit Back and the Main Menu state is activated again.
Right after the Main Menu buttons are restored, the Achievements action is AUTOMATICALLY triggered! This is very annoying, and I am basically stuck. In essence, it did not register the initial touch on the spot where the Achievements button was, since that button was disabled. But when the condition was met for that button to be 'enabled' again, then it remembered that you touched over that button while it was deactivated and triggered that button's action.
Any help, guys?
I disable the buttons by putting everything in them inside a rule saying that if game.state is "Main Menu", only then are the rules available - rules such as "if touch is released, then trigger action"
Comments
A quick and dirty way might be to move the main menu buttons off of the screen area when state is "1."
Then when state is "0" you can move the menu buttons back onto the screen area. (This will happen after the release is registered. So they won't trigger on the release.)
This could be a way, I definitely agree with you. If I do not get any more ideas I will implement this method.
Since we are on the topic, how would you implement "multiple scenes" inside the same scene? Is my method too redneck? I know that you have lots more experience than I do to this kind of thing, and I am open to learning if you're willing to share, of course.
I would recommend moving the camera around in a single scene to mimic the effect of multiple 'scenes'. For example, if you make the scene twice as wide as your screen area, you can have the 'menu scene' located all the way to the left. And then you can make your 'settings scene' on the other (right hand) side of the expanded scene. A quick camera move will switch between 'scenes.'
In the end, I just made it like this: if Settings button tapped, change CameraOriginY to 320. For scene load time optimizations, I have another spawner actor saying that when CameraOriginY is 320, it spawns the Settings page items accordingly.
Thank you! I will definitely be using this method a lot.
Glad you got it working how you want!