Skip to content

Commit 17b8ca1

Browse files
committed
Add ajiClick
1 parent 5f02dae commit 17b8ca1

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

example/audio/main.js

+6-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

player.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let ajiBG = [new Image(), new Image(), new Image(), new Image()];
1313
let ajiSprite = [];
1414
let ajiAudioContext = new AudioContext();
1515
let ajiAudio = [];
16-
let ajiMouse = { x: 0, y: 0 };
16+
let ajiMouse = { x: 0, y: 0, flag: false, count: 0 };
1717

1818
window.onload = function () {
1919
ajiInit();
@@ -34,13 +34,19 @@ function ajiInit() {
3434
setup();
3535
}
3636
ajiCanvas.addEventListener("mousedown", ajiMouseDown, false);
37+
ajiCanvas.addEventListener("mouseup", ajiMouseUp);
3738
ajiMain();
3839
}
3940

4041
function ajiMain() {
4142
const ajiNowTime = Date.now();
4243
if (ajiNowTime - ajiDrawTime >= 1000 / AJIPACK_FPS) {
4344
ajiDrawTime = ajiNowTime;
45+
if (ajiMouse.flag == true) {
46+
ajiMouse.count++;
47+
} else {
48+
ajiMouse.count = 0;
49+
}
4450
if (typeof loop == "function") {
4551
loop();
4652
}
@@ -229,4 +235,17 @@ function ajiMouseDown(e) {
229235
const rect = e.target.getBoundingClientRect();
230236
ajiMouse.x = e.clientX - rect.left;
231237
ajiMouse.y = e.clientY - rect.top;
238+
ajiMouse.flag = true;
239+
}
240+
241+
function ajiMouseUp() {
242+
ajiMouse.flag = false;
243+
}
244+
245+
function ajiClick() {
246+
if (ajiMouse.flag == true && ajiMouse.count == 1) {
247+
return true;
248+
} else {
249+
return false;
250+
}
232251
}

0 commit comments

Comments
 (0)