kaplay-ui 0.5.0 → 0.6.1

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/index.js +28 -13
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -3,37 +3,52 @@ 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 {number} x - The x postion to set.
7
- * @param {y} y - The y position to set.
8
- * @param {Function} [f] - Click event handler (default is () => {}))
9
- * @param {boolean} [hover] - Add hover effect (default is true)
6
+ * @param {Function} [onClick] - Click event handler (default is () => {}))
7
+ * @param {number} x - The x postion to set (default is center().x).
8
+ * @param {number} y - The x postion to set (default is center().y)
9
+ * @param {number} w - Width of button (default is 120)
10
+ * @param {number} h - Height of button (default is 50)
11
+ * @param {number} txtSize - Text size of button (default is 15)
12
+ * @param {boolean} [hoverFx] - Add hover effect (default is true)
10
13
  * @returns {GameObj}
11
14
  */
12
- export const addTextButton = (txt, x, y, f = () => {}, hover = true) => {
15
+ export const addTextButton = (
16
+ txt,
17
+ onClick = () => {},
18
+ x = center().x,
19
+ y = center().y,
20
+ w = 120,
21
+ h = 50,
22
+ txtSize = 15,
23
+ hoverFx = true
24
+ ) => {
25
+ // Button
13
26
  const btn = add([
14
- rect(240, 80, { radius: 8 }),
27
+ rect(w, h, { radius: 8 }),
15
28
  pos(x, y),
16
29
  area(),
30
+ scale(1),
17
31
  anchor("center"),
18
- outline(4),
32
+ outline(1),
19
33
  color(255, 255, 255),
20
34
  ]);
21
35
 
22
- // button text
23
- btn.add([text(txt), anchor("center"), color(0, 0, 0)]);
36
+ // Button text
37
+ btn.add([text(txt, { size: txtSize }), anchor("center"), color(0, 0, 0)]);
24
38
 
25
- btn.onClick(f);
39
+ // On click handler
40
+ btn.onClick(onClick);
26
41
 
27
42
  btn.onHoverUpdate(() => {
28
43
  setCursor("pointer");
29
- if (hover) {
30
- btn.scale = vec2(1.1);
44
+ if (hoverFx) {
45
+ btn.scale = vec2(1.03);
31
46
  }
32
47
  });
33
48
 
34
49
  btn.onHoverEnd(() => {
35
50
  setCursor("default");
36
- if (hover) {
51
+ if (hoverFx) {
37
52
  btn.scale = vec2(1);
38
53
  }
39
54
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kaplay-ui",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "description": "UI components for KAPLAY",
5
5
  "main": "index.js",
6
6
  "repository": {