Skip to content

Instantly share code, notes, and snippets.

@alexey-dc
Created April 17, 2013 22:01
Show Gist options
  • Select an option

  • Save alexey-dc/5408137 to your computer and use it in GitHub Desktop.

Select an option

Save alexey-dc/5408137 to your computer and use it in GitHub Desktop.
Button API
-- Production usage
local anyKindOfProp = Group.new()
local clickHandler = function(button) print("Hello", button) end
local buttonFromProp = Button.new(anyKindOfProp, clickHandler)
-- Helper functionality
local path = "assets/button.png"
local buttonWithBG = Button.createWithBackground(path, clickHandler)
buttonWithBG:setText("Click ME!")
-- Debug oriented functionality
local width, height = 120, 40
local debugButton = Button.rectangleButton(clickHandler, width, height)
debugButton:setText("NO! Click ME!)
@aab29
Copy link

aab29 commented Apr 17, 2013

The production stuff looks great! Only I would change it to accept an onTouchDown(button) and (optional) onTouchUp(button) handler.

In my opinion, the helper and debug-oriented functionality don't belong in the shared API. It doesn't take very long to create your own helper/debug methods on a per-game basis, and honestly, I haven't run into many situations where I actually needed buttons to debug a game.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment