forked from Nightwolf-47/KleleAtoms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mobile.lua
77 lines (61 loc) · 1.96 KB
/
mobile.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
local scale = 1 --Mobile scale
local res = {640,480} --Ingame resolution (units)
local sxo = 0 --Safe area X offset (avoids drawing on the notch)
local realx = 0 --Real screen width (in pixels)
local realy = 0 --Real screen height (in pixels)
local movex = 0 --move screen X pixels to the right
local isGfxPushed = false --Is scaling active or not
local mobile = {}
local isInit = false --Is mobile mode initialized or not
function mobile.init() --Initialize mobile mode
if isInit then return end
if _CAOSType == "Web" then
realx = 800
realy = 600
love.window.updateMode(realx,realy)
else
sxo = love.window.getSafeArea()
realx, realy = love.window.getDesktopDimensions()
realx = realx - sxo*2
love.window.updateMode(realx,realy,{fullscreen=true})
end
isInit = true
end
function mobile.predraw() --Setup graphics scaling
scale = math.min(realx/res[1],realy/res[2])
movex = math.floor((realx/2)-((res[1]/2)*scale))+sxo
love.graphics.push()
love.graphics.translate(movex,0)
love.graphics.scale(scale,scale)
isGfxPushed = true
end
function mobile.postdraw() --Stop graphics scaling
if isGfxPushed then
love.graphics.pop()
isGfxPushed = false
end
end
function mobile.setresolution(winx,winy) --Set ingame resolution
res = {winx,winy}
end
function mobile.getresolution() --Get ingame resolution
return res[1],res[2]
end
function mobile.convertcoords(x,y) --Convert screen coordinates to ingame coordinates
x = (x-movex)/scale
y = y/scale
return x,y
end
function mobile.absolutedrawmode(enable) --Draw without scaling and x coordinate offset
if enable and isGfxPushed then
love.graphics.pop()
isGfxPushed = false
end
if not enable and not isGfxPushed then
love.graphics.push()
love.graphics.translate(movex,0)
love.graphics.scale(scale,scale)
isGfxPushed = true
end
end
return mobile