Multitouch Button

Features demonstrated:

Multitouch and use of external libraries.

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
-- activate multitouch so multiple touches can press different buttons simultaneously
system.activate( "multitouch" )
 
local ui = require("ui")
 
local button1 = ui.newButton{
        default = "buttonRed.png",
        over = "buttonRedOver.png",
        text = "Button 1",
        emboss = true
}
 
local button2 = ui.newButton{
        default = "buttonRed.png",
        over = "buttonRedOver.png",
        text = "Button 2",
        emboss = true
}
 
local button3 = ui.newButton{
        default = "buttonRed.png",
        over = "buttonRedOver.png",
        text = "Button 3",
        emboss = true
}
 
button1.x = 160; button1.y = 160
button2.x = 160; button2.y = 240
button3.x = 160; button3.y = 320
 
-- Displays App title
title = display.newText( "Multitouch Buttons", 0, 30, "Verdana-Bold", 20 )
title.x = display.contentWidth/2                -- center title
title:setTextColor( 255,255,0 )
 
-- Determine if running on Corona Simulator
--
local isSimulator = "simulator" == system.getInfo("environment")
 
-- Multitouch Events not supported on Simulator
--
if isSimulator then
        msg = display.newText( "Multitouch not supported on Simulator!", 0, 380, "Verdana-Bold", 14 )
        msg.x = display.contentWidth/2          -- center title
        msg:setTextColor( 255,255,0 )
end