kaplay-ui 0.13.0 → 0.15.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 CHANGED
@@ -26,22 +26,6 @@ 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
-
45
29
  #### Text Button
46
30
 
47
31
  Here's some quick examples of how to add text buttons using Kaplay UI:
package/buttons/index.js CHANGED
@@ -8,6 +8,7 @@ import "kaplay/global";
8
8
  * @param {number} width - Width of button (default is 100)
9
9
  * @param {number} height - Height of button (default is 50)
10
10
  * @param {number} btnRadius - Border radius of button (default is 8)
11
+ * @param {number} outline - Button radius (default is 1)
11
12
  * @param {number} txtSize - Text size of button (default is 15)
12
13
  * @returns {GameObj}
13
14
  */
@@ -18,6 +19,7 @@ export const makeTextButton = (
18
19
  width = 100,
19
20
  height = 50,
20
21
  btnRadius = 8,
22
+ outline = 1,
21
23
  txtSize = 15
22
24
  ) => {
23
25
  // Make button
@@ -26,7 +28,7 @@ export const makeTextButton = (
26
28
  pos(x, y),
27
29
  area(),
28
30
  scale(1),
29
- outline(1),
31
+ outline(outline),
30
32
  color(255, 255, 255),
31
33
  ]);
32
34
 
@@ -43,73 +45,3 @@ export const makeTextButton = (
43
45
 
44
46
  return btn;
45
47
  };
46
-
47
- /**
48
- * Adds a clickable button icon button with hover effect
49
- * @param {string} spriteName - Sprite to use as icon
50
- * @param {Function} [onClick] - Click event handler (default is () => {}))
51
- * @param {number} x - The x postion to set (default is center().x).
52
- * @param {number} y - The x postion to set (default is center().y)
53
- * @param {number} w - Width of button (default is 48)
54
- * @param {number} h - Height of button (default is 48)
55
- * @param {boolean} [hoverFx] - Add hover effect (default is true)
56
- * @returns {GameObj}
57
- */
58
- export const addIconButton = (
59
- spriteName,
60
- onClick = () => {},
61
- x = center().x,
62
- y = center().y,
63
- w = 48,
64
- h = 48,
65
- hoverFx = true
66
- ) => {
67
- // Shadow effect
68
- const shadow = add([
69
- rect(w, h, { radius: 8 }),
70
- pos(x + 2, y + 2),
71
- area(),
72
- scale(1),
73
- anchor("center"),
74
- outline(1),
75
- color(128, 128, 128),
76
- ]);
77
-
78
- // Add button
79
- const iconBtn = add([
80
- rect(w, h, { radius: 8 }),
81
- pos(x, y),
82
- area(),
83
- scale(1),
84
- anchor("center"),
85
- outline(1),
86
- ]);
87
-
88
- // Add icon
89
- iconBtn.add([sprite(spriteName), anchor("center")]);
90
-
91
- // On click handler
92
- iconBtn.onClick(() => {
93
- setCursor("default");
94
- onClick();
95
- });
96
-
97
- // On hover effect
98
- iconBtn.onHover(() => {
99
- setCursor("pointer");
100
- if (hoverFx) {
101
- iconBtn.scale = vec2(1.03);
102
- shadow.scale = vec2(1.03);
103
- }
104
- });
105
-
106
- iconBtn.onHoverEnd(() => {
107
- setCursor("default");
108
- if (hoverFx) {
109
- iconBtn.scale = vec2(1);
110
- shadow.scale = vec2(1);
111
- }
112
- });
113
-
114
- return iconBtn;
115
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kaplay-ui",
3
- "version": "0.13.0",
3
+ "version": "0.15.0",
4
4
  "description": "UI components for KAPLAY",
5
5
  "main": "index.js",
6
6
  "repository": {