fix: mobile entry click and add fullscreen button

- Delay virtual controls creation until after game starts (ctrl overlay
  was intercepting title screen touches)
- Add touchstart handler on game container for mobile entry
- Add fullscreen button overlay in top-right corner
- Hide title text after game starts
This commit is contained in:
Mai
2026-07-04 08:36:15 +08:00
parent dfb738f406
commit 3376c3e333
3 changed files with 38 additions and 6 deletions
+30 -3
View File
@@ -123,12 +123,32 @@ game_load = async () => {
requestAnimationFrame(run_frame);
f.onclick = () => g.requestFullscreen();
g.onclick = () => {
if (!is_touch) {
// Mobile: fullscreen button overlay in top-right
if (is_touch) {
let fs_btn = document.createElement('button');
fs_btn.id = 'btn-fs';
fs_btn.textContent = '⛶';
fs_btn.onclick = () => g.requestFullscreen();
document.getElementById('g').appendChild(fs_btn);
}
// Game start handler
let start_game = () => {
// Remove the entry handler so it only fires once
g.onclick = null;
if (g._touch_entry) {
g.removeEventListener('touchstart', g._touch_entry);
g._touch_entry = null;
}
if (is_touch) {
// Create virtual controls now that game is starting
create_touch_controls();
} else {
g.onclick = () => c.requestPointerLock();
g.onclick();
}
audio_init();
// Generate sounds
@@ -157,6 +177,13 @@ game_load = async () => {
game_init(0);
run_frame = game_run;
};
// Wire up game start: click for desktop, touch for mobile
g.onclick = start_game;
if (is_touch) {
g._touch_entry = (e) => { e.preventDefault(); start_game(); };
g.addEventListener('touchstart', g._touch_entry, {passive: false});
}
},
run_frame = (time_now) => {