-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathButton.lua
More file actions
28 lines (23 loc) · 792 Bytes
/
Button.lua
File metadata and controls
28 lines (23 loc) · 792 Bytes
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
-- Button.lua
-- a little useful class for objects that know how to handle touches
Button = class(RectObj)
function Button:init(x,y,w,h)
RectObj.init(self,x,y,w,h)
self.active = true
end
function Button:onTouched(t) end -- user defined
function Button:onEnded(t) end -- user defined
function Button:onBegan(t) end -- user defined
function Button:onMoving(t) end -- user defined
-- return true if the touch was inside while this button was active, false otherwise
function Button:touched(t)
if self:inbounds(t) and self.active then
self:onTouched(t)
if t.state == BEGAN then self:onBegan(t)
elseif t.state == MOVING then self:onMoving(t)
elseif t.state == ENDED then self:onEnded(t)
end
return true
end
return false
end