kaplay-ui 0.10.0 → 0.11.0
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/README.md +16 -0
- package/buttons/index.js +0 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,6 +26,22 @@ npm install kaplay-ui
|
|
|
26
26
|
|
|
27
27
|
### Buttons
|
|
28
28
|
|
|
29
|
+
#### Icon Button
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
import kaplay from "kaplay";
|
|
33
|
+
import "kaplay/global";
|
|
34
|
+
|
|
35
|
+
import { addIconButton } from "kaplay-ui/buttons";
|
|
36
|
+
|
|
37
|
+
kaplay();
|
|
38
|
+
|
|
39
|
+
loadSprite("arrow", "sprites/arrow.png");
|
|
40
|
+
|
|
41
|
+
// Add a text button with an onClick handler
|
|
42
|
+
addIconButton("arrow", () => go("game"));
|
|
43
|
+
```
|
|
44
|
+
|
|
29
45
|
#### Text Button
|
|
30
46
|
|
|
31
47
|
Here's some quick examples of how to add text buttons using Kaplay UI:
|
package/buttons/index.js
CHANGED
|
@@ -3,7 +3,6 @@ import "kaplay/global";
|
|
|
3
3
|
/**
|
|
4
4
|
* Adds a clickable button with custom text
|
|
5
5
|
* @param {string} txt - Button text to display
|
|
6
|
-
* @param {Function} [onClick] - Click event handler (default is () => {}))
|
|
7
6
|
* @param {number} x - The x postion to set (default is center().x).
|
|
8
7
|
* @param {number} y - The x postion to set (default is center().y)
|
|
9
8
|
* @param {number} w - Width of button (default is 120)
|
|
@@ -14,7 +13,6 @@ import "kaplay/global";
|
|
|
14
13
|
*/
|
|
15
14
|
export const addTextButton = (
|
|
16
15
|
txt,
|
|
17
|
-
onClick = () => {},
|
|
18
16
|
x = center().x,
|
|
19
17
|
y = center().y,
|
|
20
18
|
w = 120,
|
|
@@ -47,12 +45,6 @@ export const addTextButton = (
|
|
|
47
45
|
// Button text
|
|
48
46
|
btn.add([text(txt, { size: txtSize }), anchor("center"), color(0, 0, 0)]);
|
|
49
47
|
|
|
50
|
-
// On click handler
|
|
51
|
-
btn.onClick(() => {
|
|
52
|
-
setCursor("default");
|
|
53
|
-
onClick();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
48
|
btn.onHover(() => {
|
|
57
49
|
setCursor("pointer");
|
|
58
50
|
if (hoverFx) {
|