Skip to content

Commit e52ae54

Browse files
committed
Mouse Partially Implemented
1 parent 89e283c commit e52ae54

File tree

8 files changed

+114
-40
lines changed

8 files changed

+114
-40
lines changed

dev/_misc/style.css

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
* {
2+
margin: 0;
3+
padding: 0;
4+
overflow: hidden;
5+
caret-color: transparent;
6+
image-rendering: crisp-edges;
7+
}
8+
9+
html {
10+
background-color: #000000;
11+
}
12+
13+
body {
14+
overflow: hidden;
15+
width: 100vw;
16+
height: 100vh;
17+
display: flex;
18+
justify-content: center;
19+
align-content: space-around;
20+
align-items: center;
21+
}
22+
23+
#PIXI {
24+
display: block;
25+
margin: 0 auto;
26+
width: 100vw;
27+
height: calc(100vw * 9 / 16);
28+
max-height: 100vh;
29+
max-width: calc(100vh * 16 / 9);
30+
}

dev/flappy-clone/index.html

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,7 @@
33

44
<head>
55
<title>Flappy Sprint</title>
6-
<style>
7-
* {
8-
margin: 0;
9-
padding: 0;
10-
overflow: hidden;
11-
caret-color: transparent;
12-
image-rendering: crisp-edges;
13-
}
14-
15-
html {
16-
background-color: "#000";
17-
}
18-
19-
body {
20-
display: flex;
21-
justify-content: center;
22-
align-items: center;
23-
}
24-
25-
#PIXI {
26-
display: block;
27-
margin: 0 auto;
28-
width: 100vw;
29-
height: calc(100vw * 9 / 16);
30-
max-height: 100vh;
31-
max-width: calc(100vh * 16 / 9);
32-
}
33-
</style>
6+
<link rel="stylesheet" type="text/css" href="../_misc/style.css">
347
<script src="https://pixijs.download/release/pixi.js"></script> <!-- This'll let me keep Zephyr VERY up to date -->
358
<script src="../zepyhr.js"></script>
369
</head>

dev/mouse-tracking/app.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const app = new PIXI.Application({ width: 480, height: 270, backgroundColor: 0xffffff, antialias: false});
2+
app.view.id = "PIXI";
3+
document.body.appendChild(app.view);
4+
5+
const sleepTex = PIXI.Texture.from('assets/sleepy.png');
6+
const rageTex = PIXI.Texture.from('assets/rage.png');
7+
8+
const scene = new PIXI.Container();
9+
app.stage.addChild(scene);
10+
11+
const cursor = new PIXI.Sprite.from(sleepTex);
12+
cursor.x = 0;
13+
cursor.y = 0;
14+
cursor.anchor = {x: 0.5, y: 0.5};
15+
scene.addChild(cursor);
16+
17+
app.ticker.add((deltaTime) => {
18+
cursor.x = (PIXI.input.getMouseX() * app.view.width + 0.5) ^ 0;
19+
cursor.y = (PIXI.input.getMouseY() * app.view.height + 0.5) ^ 0;
20+
if (PIXI.input.getMouseDown(0)) {
21+
cursor.texture = rageTex;
22+
} else {
23+
cursor.texture = sleepTex;
24+
}
25+
});

dev/mouse-tracking/assets/rage.png

697 Bytes
Loading
529 Bytes
Loading

dev/mouse-tracking/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<title>Mouse Tracking</title>
6+
<link rel="stylesheet" type="text/css" href="../_misc/style.css">
7+
<script src="https://pixijs.download/release/pixi.js"></script> <!-- This'll let me keep Zephyr VERY up to date -->
8+
<script src="../zepyhr.js"></script>
9+
</head>
10+
11+
<body>
12+
<script src="app.js"></script> <!-- Testing -->
13+
</body>
14+
15+
</html>

dev/zepyhr.js

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,32 @@ PIXI.zephyr = "ZephyrJS version 22.5.23";
44

55
PIXI.input = {
66
keyMap: new Map(),
7-
87
// getKeyFired returns true the first time it is called for a key while the key is down
98
getKeyFired: (keyStr) => {
109
let r = PIXI.input.keyMap.get(keyStr);
1110
PIXI.input.keyMap.set(keyStr, false);
1211
return r;
1312
},
14-
1513
// getKeyDown returns true always if the key is down
1614
getKeyDown: (keyStr) => {
1715
return PIXI.input.keyMap.has(keyStr);
1816
},
17+
18+
mouseMap: new Map(),
19+
getMouseFired: (btnStr) => {
20+
let r = PIXI.input.mouseMap.get(btnStr);
21+
PIXI.input.keyMap.set(btnStr, false);
22+
return r;
23+
},
24+
getMouseDown: (btnStr) => {
25+
return PIXI.input.mouseMap.has(btnStr);
26+
},
27+
getMouseX: () => {
28+
return PIXI.input.mouseMap.get('x');
29+
},
30+
getMouseY: () => {
31+
return PIXI.input.mouseMap.get('y');
32+
},
1933
}
2034

2135
PIXI.collision = {
@@ -30,22 +44,38 @@ PIXI.collision = {
3044
}
3145

3246
// https://www.w3schools.com/jsref/met_element_requestfullscreen.asp
33-
PIXI.utils.openFullScreen = (view) => { // w3schools <3
34-
if (view.requestFullscreen) {
35-
view.requestFullscreen();
36-
} else if (view.webkitRequestFullscreen) { /* Safari */
37-
view.webkitRequestFullscreen();
38-
} else if (view.msRequestFullscreen) { /* IE11 */
39-
view.msRequestFullscreen();
40-
}
47+
PIXI.utils.openFullScreen = (view) => {
48+
if (view.requestFullscreen)
49+
view.requestFullscreen(); // Standard
50+
else if (view.webkitRequestFullscreen)
51+
view.webkitRequestFullscreen(); // Safari
52+
else if (view.msRequestFullscreen)
53+
view.msRequestFullscreen(); // IE11
4154
}
4255

4356
// Keyboard
4457
window.addEventListener('keydown', (e) => {
45-
PIXI.input.keyMap.set(e.key.toUpperCase(), true);
58+
PIXI.input.keyMap.set(e.key.toLowerCase(), true);
4659
});
4760
window.addEventListener('keyup', (e) => {
48-
PIXI.input.keyMap.delete(e.key.toUpperCase())
61+
PIXI.input.keyMap.delete(e.key.toLowerCase());
62+
});
63+
64+
// Mouse
65+
window.addEventListener('mousemove', (e) => {
66+
PIXI.input.mouseMap.set('x', e.x / window.innerWidth);
67+
PIXI.input.mouseMap.set('y', e.y / window.innerHeight);
4968
});
69+
window.addEventListener('mousedown', (e) => {
70+
PIXI.input.mouseMap.set(e.button, true);
71+
});
72+
window.addEventListener('mouseup', (e) => {
73+
PIXI.input.mouseMap.delete(e.button);
74+
});
75+
76+
// Catches/Blocks right click
77+
window.addEventListener('contextmenu', (e) => {
78+
e.preventDefault();
79+
})
5080

5181
console.log(PIXI.zephyr + " is extending Pixi!");

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<h1>ZephyrJS</h1>
3838
<p class="b">Built to extend upon PixiJS!</p>
3939
<p>Links: <a href="dev/flappy-clone/index.html">Flappy Clone</a></p>
40+
<p>Links: <a href="dev/mouse-tracking/index.html">Mouse Testing</a></p>
4041
</body>
4142

4243
</html>

0 commit comments

Comments
 (0)