hytopia 0.3.13 → 0.3.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/boilerplate/assets/map.json +42 -190
- package/boilerplate/assets/ui/index.html +102 -0
- package/boilerplate/index.ts +3 -0
- package/examples/mobile-controls/README.md +3 -0
- package/examples/mobile-controls/assets/map.json +2624 -0
- package/examples/mobile-controls/assets/ui/index.html +102 -0
- package/examples/mobile-controls/bun.lock +503 -0
- package/examples/mobile-controls/index.ts +32 -0
- package/examples/mobile-controls/package.json +15 -0
- package/package.json +1 -1
@@ -0,0 +1,102 @@
|
|
1
|
+
<!--
|
2
|
+
This is a basic boilerplate example of how to implement simple game UI,
|
3
|
+
and also configure additional buttons for mobile compatibility.
|
4
|
+
-->
|
5
|
+
|
6
|
+
<script>
|
7
|
+
// Handle interact button touch / untouch
|
8
|
+
const mobileInteractButton = document.getElementById('mobile-interact-button');
|
9
|
+
mobileInteractButton.addEventListener('touchstart', e => {
|
10
|
+
e.preventDefault(); // Prevents mobile highlight/select/copy popup behaviors
|
11
|
+
mobileInteractButton.classList.add('active'); // more immediate feedback to add/remove active class
|
12
|
+
hytopia.pressInput('ml', true);
|
13
|
+
});
|
14
|
+
|
15
|
+
mobileInteractButton.addEventListener('touchend', e => {
|
16
|
+
e.preventDefault();
|
17
|
+
mobileInteractButton.classList.remove('active');
|
18
|
+
hytopia.pressInput('ml', false);
|
19
|
+
});
|
20
|
+
|
21
|
+
// Handle jump button touch / untouch
|
22
|
+
const mobileJumpButton = document.getElementById('mobile-jump-button');
|
23
|
+
mobileJumpButton.addEventListener('touchstart', e => {
|
24
|
+
e.preventDefault();
|
25
|
+
mobileJumpButton.classList.add('active');
|
26
|
+
hytopia.pressInput(' ', true);
|
27
|
+
});
|
28
|
+
|
29
|
+
mobileJumpButton.addEventListener('touchend', e => {
|
30
|
+
e.preventDefault();
|
31
|
+
mobileJumpButton.classList.remove('active');
|
32
|
+
hytopia.pressInput(' ', false);
|
33
|
+
});
|
34
|
+
</script>
|
35
|
+
|
36
|
+
<!--
|
37
|
+
HYTOPIA allows you to build completely custom UI uses HTML, CSS and Javascript.
|
38
|
+
You can build simple UIs, to highly complex ones. UI capabilities are as powerful
|
39
|
+
as building a regaulr web page - there are no limitations on what you can do.
|
40
|
+
|
41
|
+
Remember, HYTOPIA sandboxes your UI & UI scripts, so external network requests or
|
42
|
+
other unsafe actions likely won't work as you expect in production.
|
43
|
+
-->
|
44
|
+
|
45
|
+
<div class="mobile-controls">
|
46
|
+
<a id="mobile-interact-button" class="mobile-button">
|
47
|
+
<img src="{{CDN_ASSETS_URL}}/icons/target.png" />
|
48
|
+
</a>
|
49
|
+
|
50
|
+
<a id="mobile-jump-button" class="mobile-button">
|
51
|
+
<img src="{{CDN_ASSETS_URL}}/icons/jump.png" />
|
52
|
+
</a>
|
53
|
+
</div>
|
54
|
+
|
55
|
+
<style>
|
56
|
+
/* By default, we hide the mobile controls */
|
57
|
+
.mobile-controls {
|
58
|
+
display: none;
|
59
|
+
}
|
60
|
+
|
61
|
+
/*
|
62
|
+
We can use the body.mobile class to detect if we're on a mobile device.
|
63
|
+
HYTOPIA will always add this class to the body element when running on a mobile device.
|
64
|
+
*/
|
65
|
+
body.mobile .mobile-controls { /* If this css selector matches because we're on mobile, show the mobile controls */
|
66
|
+
display: flex;
|
67
|
+
gap: 14px;
|
68
|
+
position: fixed;
|
69
|
+
bottom: 40px;
|
70
|
+
right: 40px;
|
71
|
+
}
|
72
|
+
|
73
|
+
/* You can configure and style your buttons however you'd like. This is a minimalistic starting point. */
|
74
|
+
.mobile-button {
|
75
|
+
background-color: rgba(0, 0, 0, 0.5);
|
76
|
+
border-radius: 50%;
|
77
|
+
align-items: center;
|
78
|
+
justify-content: center;
|
79
|
+
display: flex;
|
80
|
+
width: 50px;
|
81
|
+
height: 50px;
|
82
|
+
transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
|
83
|
+
will-change: transform, background-color;
|
84
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
85
|
+
font-family: 'Inter', sans-serif;
|
86
|
+
font-size: 14px;
|
87
|
+
font-weight: bold;
|
88
|
+
color: rgba(255, 255, 255, 0.8);
|
89
|
+
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
|
90
|
+
}
|
91
|
+
|
92
|
+
.mobile-button img {
|
93
|
+
width: 22px;
|
94
|
+
height: 22px;
|
95
|
+
}
|
96
|
+
|
97
|
+
.mobile-button.active {
|
98
|
+
transform: scale(0.92);
|
99
|
+
background-color: rgba(0, 0, 0, 0.75);
|
100
|
+
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
|
101
|
+
}
|
102
|
+
</style>
|