Creating a widget button in corona, with a button press effect and a function call is as simple as below:
-- First, require 'widget' --
local widget = require("widget")
-- Create the button --
local myButton = widget.newButton{
default = "normalImage.png",
over = "pressedImage.png",
width = 200, height = 200,
onRelease = myButtonClickFunction
}
-- Position the button --
myButton.x = display.contentWidth/2
myButton.y = display.contentHeight/2
-- Then create the function you need to trigger on the button press --
function myButtonClickFunction()
print("myButton is pressed...")
end
-- First, require 'widget' --
local widget = require("widget")
-- Create the button --
local myButton = widget.newButton{
default = "normalImage.png",
over = "pressedImage.png",
width = 200, height = 200,
onRelease = myButtonClickFunction
}
-- Position the button --
myButton.x = display.contentWidth/2
myButton.y = display.contentHeight/2
-- Then create the function you need to trigger on the button press --
function myButtonClickFunction()
print("myButton is pressed...")
end
No comments:
Post a Comment