fixed buttons

This commit is contained in:
Alexey 2025-10-22 13:44:56 +03:00
commit f82e12cfa0

View file

@ -57,7 +57,7 @@ end
function Button:checkPoint( point ) function Button:checkPoint( point )
local px, py = point:coords() local px, py = point:coords()
local sx, sy = self.position:coords() local sx, sy = self.position:coords()
local ex, ey = self.position:coords() local ex, ey = self.size:coords()
ex = ex + sx ex = ex + sx
ey = ey + sy ey = ey + sy
return px >= sx and px <= ex and py >= sy and py <= ey return px >= sx and px <= ex and py >= sy and py <= ey
@ -69,15 +69,14 @@ end
function Button:update( dt, point, pressed ) function Button:update( dt, point, pressed )
self.prevPressed = self.lastPressed self.prevPressed = self.lastPressed
self.lastPressed = pressed self.lastPressed = pressed
local inBounds = self:checkPoint( point )
if self.lastPressed and not self.prevPressed then if inBounds then
local inBounds = self:checkPoint( point ) if self.lastPressed and not self.prevPressed then
if inBounds then
self:pressed() self:pressed()
elseif self.lastPressed and self.prevPressed then
self:held( dt )
elseif not self.lastPressed and self.prevPressed then
self:released()
end end
elseif self.lastPressed and self.prevPressed then
self:held( dt )
elseif not self.lastPressed and self.prevPressed then
self:released()
end end
end end