kaplay-ui 0.12.0 → 0.13.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.
Files changed (2) hide show
  1. package/buttons/index.js +20 -42
  2. package/package.json +1 -1
package/buttons/index.js CHANGED
@@ -1,67 +1,45 @@
1
1
  import "kaplay/global";
2
2
 
3
3
  /**
4
- * Adds a text button with shadow and hover effect
4
+ * Makes button with centered text
5
5
  * @param {string} txt - Button text to display
6
- * @param {number} x - The x postion to set (default is center().x).
7
- * @param {number} y - The x postion to set (default is center().y)
8
- * @param {number} width - Width of button (default is 120)
6
+ * @param {number} x - The x postion to set (default is 0).
7
+ * @param {number} y - The x postion to set (default is 0)
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
11
  * @param {number} txtSize - Text size of button (default is 15)
12
- * @param {boolean} [hoverFx] - Add hover effect (default is true)
13
12
  * @returns {GameObj}
14
13
  */
15
- export const addTextButton = (
14
+ export const makeTextButton = (
16
15
  txt,
17
- x = center().x,
18
- y = center().y,
19
- width = 120,
16
+ x = 0,
17
+ y = 0,
18
+ width = 100,
20
19
  height = 50,
21
20
  btnRadius = 8,
22
- txtSize = 15,
23
- hoverFx = true
21
+ txtSize = 15
24
22
  ) => {
25
- // Shadow effect
26
- const shadow = add([
27
- rect(width, height, { radius: btnRadius }),
28
- pos(x + 2, y + 2),
29
- area(),
30
- scale(1),
31
- anchor("center"),
32
- outline(1),
33
- color(128, 128, 128),
34
- ]);
35
-
36
- // Button
37
- const btn = add([
23
+ // Make button
24
+ const btn = make([
38
25
  rect(width, height, { radius: btnRadius }),
39
26
  pos(x, y),
40
27
  area(),
41
28
  scale(1),
42
- anchor("center"),
43
29
  outline(1),
44
30
  color(255, 255, 255),
45
31
  ]);
46
32
 
47
- // Button text
48
- btn.add([text(txt, { size: txtSize }), anchor("center"), color(0, 0, 0)]);
49
-
50
- btn.onHover(() => {
51
- setCursor("pointer");
52
- if (hoverFx) {
53
- btn.scale = vec2(1.03);
54
- shadow.scale = vec2(1.03);
55
- }
56
- });
33
+ // Make button text
34
+ const btnText = make([
35
+ text(txt, { size: txtSize }),
36
+ pos(width / 2, height / 2),
37
+ anchor("center"),
38
+ color(0, 0, 0),
39
+ ]);
57
40
 
58
- btn.onHoverEnd(() => {
59
- setCursor("default");
60
- if (hoverFx) {
61
- btn.scale = vec2(1);
62
- shadow.scale = vec2(1);
63
- }
64
- });
41
+ // Add text to button
42
+ btn.add(btnText);
65
43
 
66
44
  return btn;
67
45
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kaplay-ui",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "UI components for KAPLAY",
5
5
  "main": "index.js",
6
6
  "repository": {