-
Notifications
You must be signed in to change notification settings - Fork 0
/
Text.lua
47 lines (40 loc) · 1.18 KB
/
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
Text = Class{}
function Text:init(text,font,x,y,rgb,visible)
self.font = font or love.graphics.getFont()
self.centreX = x == 'centre'
self.centreY = y == 'centre'
self.text = love.graphics.newText(self.font,text)
self.width,self.height = self.text:getDimensions()
if self.centreX then
self.x = VIRTUALWIDTH / 2 - self.width / 2
else
self.x = x
end
if self.centreY then
self.y = VIRTUALHEIGHT / 2 - self.height / 2
else
self.y = y
end
self.rgb = rgb or {1,1,1}
if visible == nil then self.visible = true else self.visible = visible end
end
function Text:updateText(text,font)
if font then self.font = font end
self.text = love.graphics.newText(self.font,text)
self.width,self.height = self.text:getDimensions()
if self.centreX then
self.x = VIRTUALWIDTH / 2 - self.width / 2
end
if self.centreY then
self.y = VIRTUALHEIGHT / 2 - self.height / 2
end
end
function Text:update()
end
function Text:render()
if self.visible then
love.graphics.setColor(self.rgb)
love.graphics.draw(self.text, self.x, self.y)
love.graphics.setColor(1,1,1)
end
end