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.
- package/buttons/index.js +20 -42
- package/package.json +1 -1
package/buttons/index.js
CHANGED
|
@@ -1,67 +1,45 @@
|
|
|
1
1
|
import "kaplay/global";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
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
|
|
7
|
-
* @param {number} y - The x postion to set (default is
|
|
8
|
-
* @param {number} width - Width of button (default is
|
|
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
|
|
14
|
+
export const makeTextButton = (
|
|
16
15
|
txt,
|
|
17
|
-
x =
|
|
18
|
-
y =
|
|
19
|
-
width =
|
|
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
|
-
//
|
|
26
|
-
const
|
|
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
|
-
//
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
59
|
-
|
|
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
|
};
|