Funny you should say that… We actually have some “button” classes but I didn’t want to confuse people by adding another layer of abstracted classes in. Our button classes do few cool things:
-
Listen for mouse events and get scale up on mouseOver
-
Listen to touch events and scale down on push
-
Listen to keyPress events for a shortCut key
-
Broadcast “pressed” and “released” events that have an event.buttonName that pass the name of the button
So it becomes super-simple to build a UI with a single listener that has something like this in it
onUI(event) local phase, name = event.phase, event.buttonName if phase == "released" then if name == "play" then composer.gotoScene( "scene.game" ) end end end Runtime:addEventListener("UI", onUI)
In the game we are currently working on, we build all of our UI (including level select) in tiled, but I haven’t refactored it into the new UI classes. Once I do, I’ll have a nice test case to work with…
Eventually I’d like to build toggles, sliders, etc. and release a Tiled GUI project.