Here's an example of a typical mobile game level select menu. I hope to discover if the whole thing is doable using the Command/Timeline system, and if there's a better way than the way I imagine it.
I have already implemented all the behavior described here using orx in a config-driven way, but since the timeline system is adopted by the community and will be developed further, it's worth using it for the next set of menus if possible.
- User has several "pages" of menu items they can flip through using a swipe gesture or on screen buttons
This part is easily doable with timelines. All on and offscreen pages are contained in one big orx object. When the user swipes or taps, the C code adds a timeline to the object that makes it scroll left or right, giving the appearance of page changes. Comments?
- Tapping a menu item either opens another menu system or starts gameplay
Again, easy to do with timelines. A timeline can be created that destroys the previous menu and creates a new menu. When the user taps a menu option, the C code adds that timeline to the menu object and the menu switch happens. Comments?
- Conditional logic for the paging system 1, i.e. the user is not allowed to scroll before the first page or after the last page. In this case, the "scroll" action must be canceled.
How can this be done with timelines? How can the timeline "know" the user is already on the first page and cancel the scrolling action? The number of pages and current page can be stored in config, but how do we use the data?
- Conditional logic for the paging system 2, i.e. when a user is on a certain "page" or taps a "level" graphic, we might want to display a page counter or show the name of the level. We can store the number of pages and a list of level names in config, but can we make this conditional functionality without resorting to the code?
Thanks for any thoughts.
Comments
For your system 1, I'd have a OnSwipeTracks property on the objects that support swiping, and it's a list of 2 elements: 1st one is for swiping left, second one is for swiping right.
Left most object would then have an empty first element and right most one an empty second element.
This way in code, when detecting a swipe left movement, you check if the object has the property OnSwipeTracks and if the 1st element is non-empty. If so, you add it as a timeline track on the object. Idem for swiping right with the second element.
For the system 2, I'm not exactly sure where you need some conditionals. I'd add a OnClickTrack property on objects that can be clicked and would add the timeline track to it when found.
In this case you can have different tracks doing different things, like displaying a name or anything else. That's how I handle all our buttons, menu and tutorials in my current WIP game: I have an OnClickTrack property for objects that can be interacted with and the code simply gets the picked object when the "Action" input has been activated and add the corresponding track if the property is not empty.
I plan on adding OnReleaseTrack to handle both click and click+release for things like icons changes, etc.
When the config tracks needs to call some code, I simply use the input module to interface.
For example my MusicOnTrack and MusicOffTrack that are executed when we click on the mute/un-mute music buttons trigger the code with the command "Input.SetValue ToggleMusic true" when it has dealt with UI modifications (ie. deleting current button and creating the opposite one and setting the current menu as its owner).
Hope this helps!
OnPressed: used when the user click the item (usually trigger a short animation / FX to show to the user which item he is clicking at)
OnClick: used to trigger the actions (start game / quit game / show another part of the menu scene), only fired when the user release the click inside the item graphic.
OnReleased: the opposite of OnPressed to reset the item state. fired either because the user released the click inside the item graphic, or because the user moved the pointer outside the item graphic while clicking.
For system 2, I'm thinking of a paged system, where swiping left and right causes the graphics to move and also update text or another object based on which page is currently visible.
So, as an example, you swipe between "Level 1" and "Level 2" and a text caption updates to show the correct text. In this case, the system has to know what page the player is on and what text is appropriate to display for that page.
In config you could store a list of strings that correspond to the correct text for each level. Then the program somehow has to decide which page the player is on, find the correct text in the list, and draw it.
I see there's a Config.SetValue command. Is there a command to do something like a increment/decrement operation for Config values?
Also, it looks like I can register my own commands and use them in timetracks.. is that right? Is there a simple working example posted?
Thanks again
So I might be able to take care of my conditional stuff by registering my own commands? This is similar to the pattern I'm currently using to do this type of thing, but I am interested in doing it the orx way, so as to easily take advantage of new features as they come.
Right now, you can either register a command and call it from the timeline (registering a command is pretty straightforward, you can look inside orxObject.c, orxLocale.c or orxConfig.c to see how I did it, or you can simply execute some code when an input is activated.
For example you can have the input SwipeLeft and SwipeRight that would be triggered from the timeline and handled in code, either for doing the whole processing or barely to update the current index in the list, store it in config and then reuse it from the timeline side.
Not optimal but while there are no Maths. command that could be a work around.
Something that would read a block of text and create the timelines from it, handling the stack and using the config system for storing local variables.
I'm not there yet but that might be more user friendly. What do you think?
And I guess I can push values onto the stack and then send them to my own registered command? So if I registered a command called CustomSwipeFunction that accepted three parameters, the current page the player is on, the FX I want to apply when scrolling, and the object to scroll, could I call it like this from a timeline:
[ScrollRightTrack]
> Config.GetValue O-SwipeArea currentPage #
> Config.GetValue O-SwipeArea scrollFX #
> ^ #
CustomSwipeFunction < < <
Not that I'd necessarily have one command do so much, but would the above example work?
So would this script layer in scroll read a text block from config? How would that block be formatted?
I personally use inputs as I'm lazy.
Yep, it looks just fine to me.
Yes, a text block from config, like shaders, with the option to process it programmatically too.
Not sure about the syntax/formatting yet, but something that would abstract all the push/popping with named variables and look like a basic scripting language.
Anyway it's not a top priority now, but it might help those who think timelines are a bit hard to use at the moment.