kaplay-ui 0.17.0 → 0.18.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/assets/cb-icon.png +0 -0
- package/inputs/index.js +41 -0
- package/package.json +1 -1
|
Binary file
|
package/inputs/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import "kaplay/global";
|
|
2
2
|
|
|
3
|
+
import cbIcon from "../assets/cb-icon.png";
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Makes button with centered text
|
|
5
7
|
* @param {string} txt - Button text to display
|
|
@@ -90,3 +92,42 @@ export const makeToggle = (x = 0, y = 0, width = 50, height = 25) => {
|
|
|
90
92
|
|
|
91
93
|
return toggle;
|
|
92
94
|
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Makes checkbox
|
|
98
|
+
* @param {number} x - The x postion to set (default is 0)
|
|
99
|
+
* @param {number} y - The x postion to set (default is 0)
|
|
100
|
+
* @param {number} width - Checkbox width (default is 50)
|
|
101
|
+
* @param {number} height - Checkbox height (default is 50)
|
|
102
|
+
* @returns {GameObj}
|
|
103
|
+
*/
|
|
104
|
+
export const makeCheckbox = (x = 0, y = 0, width = 50, height = 50) => {
|
|
105
|
+
loadSprite("cb", cbIcon);
|
|
106
|
+
|
|
107
|
+
const checkbox = make([
|
|
108
|
+
rect(width, height, { radius: 4 }),
|
|
109
|
+
pos(x, y),
|
|
110
|
+
color(255, 255, 255),
|
|
111
|
+
outline(1),
|
|
112
|
+
area(),
|
|
113
|
+
{
|
|
114
|
+
checked: false,
|
|
115
|
+
},
|
|
116
|
+
]);
|
|
117
|
+
|
|
118
|
+
const checkedIcon = make([sprite("cb", { width, height }), area()]);
|
|
119
|
+
|
|
120
|
+
checkbox.onClick(() => {
|
|
121
|
+
if (checkbox.checked) {
|
|
122
|
+
checkbox.use(color(255, 255, 255));
|
|
123
|
+
checkbox.remove(checkedIcon);
|
|
124
|
+
checkbox.checked = false;
|
|
125
|
+
} else {
|
|
126
|
+
checkbox.use(color(148, 188, 236));
|
|
127
|
+
checkbox.add(checkedIcon);
|
|
128
|
+
checkbox.checked = true;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
return checkbox;
|
|
133
|
+
};
|