MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / updateVirtualButton

Function updateVirtualButton

src/mobile/index.ts:201–241  ·  view source on GitHub ↗
(btn: VirtualButton)

Source from the content-addressed store, hash-verified

199}
200
201export function updateVirtualButton(btn: VirtualButton): void {
202 const touchCount = getTouchCount();
203 const wasActive = btn.active;
204
205 // Check if any unclaimed touch is inside the button
206 let nowActive = false;
207 let activeIndex = -1;
208
209 for (let i = 0; i < touchCount; i++) {
210 if (claimedTouches.has(i)) continue;
211 const tx = getTouchX(i);
212 const ty = getTouchY(i);
213 if (tx === 0 && ty === 0) continue;
214
215 const dx = tx - btn.x;
216 const dy = ty - btn.y;
217 if (dx * dx + dy * dy <= btn.radius * btn.radius) {
218 nowActive = true;
219 activeIndex = i;
220 break;
221 }
222 }
223
224 if (nowActive) {
225 claimedTouches.add(activeIndex);
226 btn.touchIndex = activeIndex;
227 }
228
229 if (nowActive && !wasActive) {
230 // Just pressed
231 btn.active = true;
232 if (btn.key !== null) injectKeyDown(btn.key);
233 if (btn.gamepadButton !== null) injectGamepadButtonDown(btn.gamepadButton);
234 } else if (!nowActive && wasActive) {
235 // Just released
236 btn.active = false;
237 btn.touchIndex = -1;
238 if (btn.key !== null) injectKeyUp(btn.key);
239 if (btn.gamepadButton !== null) injectGamepadButtonUp(btn.gamepadButton);
240 }
241}
242
243export function drawVirtualButton(btn: VirtualButton): void {
244 const bgColor: Color = btn.active

Callers

nothing calls this directly

Calls 7

getTouchCountFunction · 0.90
getTouchXFunction · 0.90
getTouchYFunction · 0.90
injectKeyDownFunction · 0.90
injectGamepadButtonDownFunction · 0.90
injectKeyUpFunction · 0.90
injectGamepadButtonUpFunction · 0.90

Tested by

no test coverage detected