This repository was archived by the owner on Apr 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathandroid.lua
More file actions
88 lines (66 loc) · 1.87 KB
/
Copy pathandroid.lua
File metadata and controls
88 lines (66 loc) · 1.87 KB
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
78
79
80
81
82
83
84
85
86
87
88
traceGhost = 1
-- Record rate (every x seconds)
recRate = 0.2
tt = {}
for i=1, 10 do
tt[i] = {}
tt[i].isOn = false
end
function love.touchpressed(id, x, y, pressure)
tt[id+1].isOn = true
tt[id+1].ox = x * getW / scale
tt[id+1].oy = y * getH / scale
tt[id+1].lastRecTime = love.timer.getTime()
tt[id+1].rx = x * getW / scale
tt[id+1].ry = y * getH / scale
end
function love.touchreleased(id, x, y, pressure)
tt[id+1].zx = x * getW / scale
tt[id+1].zy = y * getH / scale
tt[id+1].isOn = false
end
function touchRecord()
for i = 1, love.touch.getTouchCount() do
tt[i].id, tt[i].x, tt[i].y, tt[i].pressure = love.touch.getTouch(i)
-- Convert this to viewport coordinates
tt[i].x = tt[i].x * getW / scale
tt[i].y = tt[i].y * getH / scale
-- Enable ghost tracing to trace direction of touch movement
if traceGhost == 1 and love.timer.getTime() - tt[i].lastRecTime > recRate then
tt[i].lastRecTime = love.timer.getTime()
tt[i].rx = tt[i].x
tt[i].ry = tt[i].y
end
end
end
function multiplatformResize()
if love.system.getOS() == "Windows" then
love.window.setMode(1280, 720)
winW = 1280
winH = 720
end
if love.system.getOS() == "Android" then
love.window.setMode(0, 0)
scale = love.graphics.getWidth()/1280
-- setting constants to facilitate coding
ratio = love.graphics.getWidth()/love.graphics.getHeight()
winW = 1280
winH = winW / ratio
-- shortcuts to these long commands
getW = love.graphics.getWidth()
getH = love.graphics.getHeight()
end
end
function mobileScale()
if love.system.getOS() == "Android" then love.graphics.scale(scale) end
end
function Tapped(x, y, xH, yH)
for i=1, love.touch.getTouchCount() do
if tt[i].isOn then
if tt[i].ox >= x and tt[i].ox < xH and tt[i].oy >= y and tt[i].oy < yH
-- and tt[i].zx >= x and tt[i].zx < xH and tt[i].zy >= y and tt[i].zy < yH
then
return true end
end
end
end