I’m not sure whether you can do a group function like that. Ansca’s button library code (modified a bit) targets each button individually…
[code]
–button code
– Text for demo output
local tx = display.newText( “Get Ready”, 0, 0, nil, 12 )
tx:setTextColor( 255, 255, 136, 255 )
[code]
– Trick to create centered text
local group = display.newGroup()
group:insert( tx, true )
group:translate( 0.5*screenW, 0.1*screenH )
[code]
– Create 2 buttons
[code]
– You can replace the following with your own code/assets
[code]
local button1Press = function( event )
–tx.text = “Button 1 pressed”
end
[code]
local button1Release = function( event )
–tx.text = “Button 1 released”
end
[code]
local button2Press = function( event )
–tx.text = “Button 2 pressed”
end
[code]
local button2Release = function( event )
–tx.text = “Button 2 released”
end
[code]
local button1 = ui.newButton{
default=“button.png”,
rollover=“button_over.png”,
onPress=button1Press,
onRelease=button1Release,
}
[code]
local button2 = ui.newButton{
default=“button.png”,
rollover=“button_over.png”,
onPress=button2Press,
onRelease=button2Release,
}
[code]
– A layout trick to make buttons equally spaced horizontally
[code]
– Create an array for convenience and add buttons to it
local buttons = {}
buttons[#buttons + 1] = button1
buttons[#buttons + 1] = button2
[code]
local numButtons = #buttons
[code]
– Solving for buttonSpacing: screenW = (numButtons+1)*buttonSpacing + numButtons*buttonW
local buttonW = buttons[1].width
local buttonSpacing = ( screenW - numButtons*buttonW ) / ( numButtons + 1 )
[code]
– Layout buttons evenly across width of screen
local x = buttonSpacing + 0.5*buttonW
local y = screenH*0.93
for i=1,numButtons do
local button = buttons[i]
button.x = x
button.y = y
x = x + buttonSpacing + buttonW
end
[code]
–end button code
And see the Follow Me sample code for touch handling. [import]uid: 1560 topic_id: 376 reply_id: 689[/import]