-
Notifications
You must be signed in to change notification settings - Fork 0
/
text.lua
51 lines (37 loc) · 985 Bytes
/
text.lua
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
43
44
45
46
47
48
49
50
51
require "utils"
local Text = {}
function Text:new(text,x,y,scale,obj)
obj = obj or {}
setmetatable(obj,self)
self.__index = self
self.x = x
self.y = y
self.defaulX = self.x
self.defaulY = self.y
self.text = text
self.hoverOver = false
self.font = love.graphics.getFont()
self.scale = scale or 1
self.color = {1,1,1,1}
self.effects = {}
self.onClick = function () end
return deepcopy(obj)
end
function Text:setY(y)
self.y = y
end
function Text:setX(x)
self.x = x
end
function Text:update()
self.hoverOver = (love.mouse.getX() > self.x and love.mouse.getX() < self.x + self.font:getWidth(self.text)) and
(love.mouse.getY() > self.y and love.mouse.getY() < self.y + self.font:getHeight())
end
function Text:draw()
local y = self.y
if type(y) == 'table' then
y = y.y
end
love.graphics.print(self.text,self.x,y,0,self.scale,self.scale)
end
return Text