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
|
local cam = {
x = 0, y = 0,
scale = 256,
panning = false,
}
local function view_scale()
local w, h = love.graphics.getDimensions()
return cam.scale / math.min(w, h)
end
local function view_transform()
local scale = view_scale()
local trans = love.math.newTransform(0, 0, 0, 1/scale, 1/scale)
trans:translate(cam.x, cam.y)
return trans
end
function love.draw()
love.graphics.clear(0,0,0)
love.graphics.applyTransform(view_transform())
love.graphics.setColor(1, 1, 1)
love.graphics.ellipse("fill", 10, 10, 1, 1)
end
function love.mousepressed(_, _, button)
if button == 2 then
cam.panning = true
end
end
function love.mousereleased(_, _, button)
if button == 2 then
cam.panning = false
end
end
function love.mousemoved(_, _, dx, dy)
if cam.panning then
local scale = view_scale()
dx, dy = dx * scale, dy * scale
cam.x = cam.x + dx
cam.y = cam.y + dy
end
end
|