-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-webgl.html
More file actions
121 lines (106 loc) · 3.02 KB
/
test-webgl.html
File metadata and controls
121 lines (106 loc) · 3.02 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<html>
<head>
<title>Test GA 4</title>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-YM4SP4CCG6"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-YM4SP4CCG6');
</script>
<style>
body {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
canvas {
border: 1px solid red;
}
h1 {
color: blue;
font-size: 72px;
;
}
</style>
</head>
<body>
<canvas id="canvas" />
<h1>Game</h1>
<h2>Content</h2>
<button onclick="button1Click()">HTML button</button> <br><br>
<script>
function button1Click() {
gtag('event', 'submit-avatar', {
'app_name': 'Tiger',
'screen_name': 'Login'
});
console.log("button1Click")
}
function button2Click() {
gtag('event', 'button2-click', {
'app_name': 'Tiger',
'screen_name': 'Play'
});
console.log("button2Click")
}
</script>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
// create circles to draw
const buttons = [
{
x: 40,
y: 40,
width: 150,
height: 40,
color: 'rgb(255,0,0)',
text: 'Button GL 1'
},
{
x: 40,
y: 100,
width: 150,
height: 40,
color: 'rgb(255,0,255)',
text: 'Button GL 2'
}
];
buttons.forEach(b => {
ctx.beginPath();
ctx.rect(b.x, b.y, b.width, b.height);
ctx.fillStyle = b.color;
ctx.fill();
ctx.fillStyle = 'white';
ctx.font = "14px Arial";
ctx.fillText(b.text, b.x + b.width / 4, b.y + b.height / 1.6);
});
function isIntersect(pos, btn) {
if ( (pos.x >= btn.x && pos.x < btn.x + btn.width) && (pos.y >= btn.y && pos.y < btn.y + btn.height)) {
return true;
}
return false;
}
canvas.addEventListener('click', (e) => {
const pos = {
x: e.clientX,
y: e.clientY
};
buttons.forEach((b, i) => {
if (isIntersect(pos, b)) {
if(b.text === "Button GL 1") {
button1Click()
}
else if(b.text === "Button GL 2") {
button2Click()
}
}
});
});
</script>
</body>
</html>