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