-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPerspExample.lua
48 lines (38 loc) · 1.58 KB
/
PerspExample.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
---------------------------------------------------------------------------------------------------
-- Setup
local loader = require("AdvTiledLoader.Loader")
loader.path = "maps/"
local map = loader.load("perspective_walls.tmx")
---------------------------------------------------------------------------------------------------
local PerspExample = {}
---------------------------------------------------------------------------------------------------
-- Resets the example
function PerspExample.reset()
global.tx = 0
global.ty = 0
end
---------------------------------------------------------------------------------------------------
-- Called from love.draw()
function PerspExample.draw()
-- Set sprite batches
map.useSpriteBatch = global.useBatch
-- Scale and translate the game screen for map drawing
local ftx, fty = math.floor(global.tx), math.floor(global.ty)
love.graphics.push()
love.graphics.scale(global.scale)
love.graphics.translate(ftx, fty)
-- Limit the draw range
if global.limitDrawing then
map:autoDrawRange(ftx, fty, scale, -100)
else
map:autoDrawRange(ftx, fty, scale, 50)
end
-- Draw the map and the outline of the drawing area. If benchmark is checked then it draws 20 times.
map:draw()
if global.benchmark then for i=1,19 do map:draw() end end
love.graphics.rectangle("line", map:getDrawRange())
-- Reset the scale and translation.
love.graphics.pop()
end
---------------------------------------------------------------------------------------------------
return PerspExample