kaplay-ui 0.3.0 → 0.4.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 (3) hide show
  1. package/README.md +4 -2
  2. package/index.js +14 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -20,16 +20,18 @@ npm install kaplay-ui
20
20
 
21
21
  ## 🛠️ Usage
22
22
 
23
- Here’s a quick example of how to add a simple clickable button using Kaplay UI:
23
+ Here’s a quick example of how to add a simple clickable and hoverable text button using Kaplay UI:
24
24
 
25
25
  ```javascript
26
26
  import kaplay from "kaplay";
27
+ import "kaplay/global";
28
+
27
29
  import { addTextButton } from "kaplay-ui";
28
30
 
29
31
  kaplay();
30
32
 
31
33
  // Add a UI button
32
- addTextButton(center().x, center().y, "start", () => go("game"));
34
+ addTextButton(center().x, center().y, "start");
33
35
  ```
34
36
 
35
37
  ## 📄 License
package/index.js CHANGED
@@ -2,14 +2,14 @@ import "kaplay/global";
2
2
 
3
3
  /**
4
4
  * Adds a clickable button with custom text
5
+ * @param {string} txt - Button text to display
5
6
  * @param {number} x - The x postion to set.
6
7
  * @param {y} y - The y position to set.
7
- * @param {string} txt - Button text to display
8
8
  * @param {Function} [f] - Click event handler (default is () => {}))
9
9
  * @param {boolean} [hover] - Add hover effect (default is true)
10
10
  * @returns {GameObj}
11
11
  */
12
- export const addTextButton = (x, y, txt, f = () => {}, hover = true) => {
12
+ export const addTextButton = (txt, x, y, f = () => {}, hover = true) => {
13
13
  const btn = add([
14
14
  rect(240, 80, { radius: 8 }),
15
15
  pos(x, y),
@@ -17,9 +17,20 @@ export const addTextButton = (x, y, txt, f = () => {}, hover = true) => {
17
17
  anchor("center"),
18
18
  outline(4),
19
19
  color(255, 255, 255),
20
+ z(10),
21
+ ]);
22
+
23
+ // Shadow effect
24
+ btn.add([
25
+ pos(x, y).add(3, 3),
26
+ rect(240, 80),
27
+ color(0, 50, 150),
28
+ anchor("center"),
29
+ z(5),
20
30
  ]);
21
31
 
22
- btn.add([text(txt), anchor("center"), color(0, 0, 0)]);
32
+ // button text
33
+ btn.add([text(txt), anchor("center"), color(0, 0, 0), z(15)]);
23
34
 
24
35
  btn.onClick(f);
25
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kaplay-ui",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "UI components for KAPLAY",
5
5
  "main": "index.js",
6
6
  "repository": {