In Codea 1.4.4 there should be a self.tapped command to easily make buttons. Like this:
function Button:touched(touch)
if self.tapped then
print("Tapped Button")
else
print("Tapped Elsewhere")
end
end
In Codea 1.4.4 there should be a self.tapped command to easily make buttons. Like this:
function Button:touched(touch)
if self.tapped then
print("Tapped Button")
else
print("Tapped Elsewhere")
end
end
But there’s probably some syntax that does that I’m new to lua.
It is not clear to me what something built-in could usefully add compared to a button-specific Button:isHit(touch)
function added to your Button
class. If you search this forum, or other Codea-related materials, you will find a lot of advice on buttons. The pattern below may be of some help:
function Button:init(name, position, onTouch, parent)
self.name = name
self.position = position
self.onTouch = onTouch -- a function called when button touched
self.parent = parent -- in some cases, you may want to keep track of the parent
...
end
function Button:isHit(touch)
if [hit logic, based on self.position] then
return true
end
return false
end
function Button:touched(touch)
if touch.state == BEGAN and self:isHit(touch) then
self:onTouch()
return true -- Returns true if touch was handled
end
return false
end
function setup()
...
onTouch = function (self)
print("Button named "..self.name.." was touched!")
end
myButton1 = Button("Button 1", position, onTouch, nil)
...
end
function touched(touch)
...
if myButton1:touched(touch) then -- Pass touch to myButton
-- Do something if touch was handled by button
else
-- Do something else if touch was not handled by button
end
...
end
I’m eleven years old anyway, so yeah…
I would lock this considering I made a button tutorial that uses only a couple lines of code, but I’m not a mod…