Control Manager

About Monkey 2 Forums Monkey 2 Code Library Control Manager

This topic contains 1 reply, has 2 voices, and was last updated by  regulark 1 year, 6 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #11040

    Anatol
    Participant

    I created a simple yet very flexible class to deal with controls, it can best be described as, “when a certain condition is met then perform an action”.

    I’m using it for user controls, e.g. when you touch the screen or press a key or rotate the device, then do something to the player sprite, etc. But it’s not limited to user input, it works for any type of condition.

    It’s basically just stuff you would otherwise put into the OnRender loop, which works just the same, but I prefer to have these conditions and commands packaged in one place. Plus, you add every control with a reference key, so you can then disable and enable the these controls easily. Again, nothing you couldn’t do in the OnRender loop, but I find this approach a bit cleaner. I’m using it with Lambda functions, but could be done otherwise as well.

    Just create an instance, …

    … add controls …

    … and call …

    … in the OnRender loop.

    If you want to disable the control/s later you just do

    for a specific control or for all

    and then enable them in the same way.

    Here’s a demo with various control examples: https://github.com/anatolbogun/monkey2-utils/blob/master/demos/control_manager_demo/main.monkey2#L61-L121

    #11041

    regulark
    Participant

    Very nice, thanks for sharing Anatol.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.