-
Notifications
You must be signed in to change notification settings - Fork 0
/
tiledbackground.lua
61 lines (42 loc) · 1.39 KB
/
tiledbackground.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
52
53
54
55
56
57
58
59
60
61
local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local math = _tl_compat and _tl_compat.math or math; require("globals")
require("love")
local gr = love.graphics
TiledBackround = {}
local TiledBackround_mt = {
__index = TiledBackround,
}
function TiledBackround.new()
local self = setmetatable({}, TiledBackround_mt)
self.img = gr.newImage(SCENEPREFIX .. "gfx/tile1.png")
self:prepareDrawing()
return self
end
function TiledBackround:prepareDrawing()
local w, h = gr.getDimensions()
self.canvas = gr.newCanvas(w, h)
gr.clear(0, 0, 0, 0)
gr.setColor({ 1, 1, 1 })
gr.setCanvas(self.canvas)
local cam = require("camera").new()
cam:zoom(0.12)
local maxi, maxj = math.ceil(h / (self.img:getHeight() * cam.scale)), math.ceil(w / (self.img:getWidth() * cam.scale))
local k = 1 / cam.scale
cam:lookAt((w / 2) * k, (h / 2) * k)
cam:attach()
for i = 0, maxi do
for j = 0, maxj do
gr.draw(self.img, j * self.img:getWidth(), i * self.img:getHeight())
end
end
cam:detach()
gr.setCanvas()
end
function TiledBackround:draw(alpha)
gr.clear(0, 0, 0, 0)
gr.setColor(1, 1, 1, alpha or 1)
gr.draw(self.canvas, 0, 0)
end
function TiledBackround:resize(_, _)
self:prepareDrawing()
end
tiledback = TiledBackround.new()