-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.lua
More file actions
42 lines (35 loc) · 918 Bytes
/
button.lua
File metadata and controls
42 lines (35 loc) · 918 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Class = require "lib/hump.class"
Button = Class {
init = function(self, x, y, img)
self.x = x
self.y = y
self.img = img
self.ex = x + 333
self.ey = y + 115
end,
hovered = false, -- Pasamos el mouse arriba
clicked = false, -- Hicimos click
darken = 0.15 -- Cuanto oscurecemos el boton
}
function Button:update(dt)
mx, my = love.mouse.getPosition()
-- El mouse esta arriba del boton
if mx > self.x and mx < self.ex and my > self.y and my < self.ey then
print("Hovered")
self.hovered = true
else
self.hovered = false
end
end
function Button:draw()
-- Si el boton esta seleccionado, hacerlo mas brillante
if self.hovered then
love.graphics.setColor(1, 1, 1, 1)
else
love.graphics.setColor(1-self.darken, 1-self.darken, 1-self.darken, 1)
end
-- Renderizar el boton
love.graphics.draw(self.img, self.x, self.y)
-- Resetear el color
love.graphics.setColor(255, 255, 255, 255)
end