ប្រើ prompt free តែមួយ ដើម្បីដាក់ controller support ពេញលេញឲ្យ game លើ browser
ប្រើ prompt វែងតែមួយ ធ្វើឲ្យ AI coding tool ថែម gamepad support ពេញលេញឲ្យ game លើ browser របស់អ្នក។
របៀបប្រើ
- បើក folder game របស់អ្នកក្នុង Claude Code ឬ AI coding tool ផ្សេងទៀត។
- Paste prompt ចូល។
- ចាំឲ្យ AI រៀបរាប់ input និង screen ឲ្យអស់សិន។
- សាកលេង game ទាំងមូលដោយប្រើតែ controller។
Add full gamepad support to this browser game. A player with only a controller must be able to do everything a keyboard and mouse player can: start the game, change every setting, play, pause, type a name, and get back to the title screen. Keyboard and mouse must keep working exactly as before.
First, read the code and write down two lists:
1. Every input the game uses: each key, mouse button, mouse move, click and hover, and what it does.
2. Every screen and popup: title, menus, settings, pause, game over, dialogs, text fields, and anything that only shows on hover.
Every item on both lists needs a gamepad way to reach it. Don't skip any.
Reading the controller:
- Use the browser Gamepad API. No new libraries.
- Call navigator.getGamepads() every frame, also while paused and in menus. Don't keep the Gamepad object from the gamepadconnected event, it goes stale.
- Use the first connected pad that has pressed a button. Handle a pad plugged in or unplugged at any time. Browsers only report a pad after a button press, so the game must not need one at load.
- With mapping "standard", use the standard layout: buttons[0] south, [1] east, [2] west, [3] north, [4]/[5] bumpers, [6]/[7] triggers, [8] back/select, [9] start, [12]-[15] D-pad, axes 0/1 left stick, 2/3 right stick. If mapping is not "standard", still treat buttons 0-3 as the face buttons and axes 0/1 as the left stick.
- Sticks: a round dead zone of about 0.2, rescaled so movement starts smoothly. Analog movement if the game can use it. The D-pad moves too.
- Feed the pad into the same input state the keyboard already uses, so the game logic doesn't change.
- Menu actions fire once on press, not every frame while held. When a button closes a menu, swallow it until it is released, so it doesn't also jump or shoot.
Button layout (by position, so it works on Xbox, PlayStation and Switch pads):
- South confirms and is the main action (jump). East goes back and cancels. West and north get the next most used actions.
- Start opens and closes pause. Back/select can restart or open a map, if the game has one.
- Every keyboard action gets a button. If there are more actions than buttons, use bumpers and triggers, or put rare actions in the pause menu.
Menus without a mouse:
- The D-pad and left stick move a visible focus highlight between items. Holding a direction repeats after about 0.4 s, then every 0.12 s. Up and down move between rows; left and right change the value of the focused row.
- When any screen opens, focus its first item (or the last one used on that screen). The focus highlight must be big and obvious, not a thin browser outline.
- South presses the focused item. East always goes back one screen. On the pause menu east resumes the game. Back must work on every screen.
- Sliders: left and right change the value in steps. Checkboxes: south toggles. Dropdowns (<select>): a browser dropdown can't be opened with a pad, so let left and right cycle the options in place.
- Anything that only appears on mouse hover (tooltips, extra info) must also appear when the item has focus.
- Don't turn the stick into a fake mouse cursor for menus.
Text fields:
- If a screen asks the player to type (a name, a code), give the pad an on-screen keyboard: a grid of letters, numbers, space, delete and done, moved with the D-pad, south types, east deletes, start or "done" confirms. Keep a physical keyboard working in the same field.
Button prompts:
- Track the last device the player touched. If it was the pad, every hint in the game shows pad buttons; if it was a key or the mouse, show the keyboard hints again. Change "Press R", "ESC to pause", "WASD to move" and every other key hint.
- Pick the button names from gamepad.id: Xbox (or unknown) A B X Y; PlayStation (contains "054c", "DualSense" or "DualShock") Cross Circle Square Triangle; Nintendo (contains "057e") B A Y X for the same positions. Draw them as small round badges with HTML/CSS or inline SVG, coloured like the real buttons, not as plain text in brackets.
- While the pad is in use, hide the mouse cursor and ignore mouse hover. Moving the mouse brings it back.
Safety:
- If the pad disconnects during play, pause the game and show "Controller disconnected".
- When the page loses focus, release every held input, so nothing gets stuck.
- If the browser offers vibrationActuator, add a short light rumble on important moments (a pickup, a hit) and a setting to turn it off. Skip it if the API is missing.
Before you finish, check your own work as a player with only a controller: start from the title, open and change every setting, go back, play, pause, resume, restart, quit to the title, finish a round and type a name. No step may need the keyboard or the mouse. Then check that keyboard and mouse still work as before.
Then tell me what you mapped to which button, and anything you couldn't map. អានបន្ថែម
សង្ខេប
Gamejam (@ShipOnGamejam លើ X) បានសរសេរអត្ថបទមួយពីការដាក់ gamepad support ក្នុង game លើ browser។ គ្រាន់តែឲ្យតួអង្គដើរគឺមិនទាន់គ្រាន់ទេ គឺរាល់ menu ទាំងអស់ត្រូវតែមាន highlight ឲ្យច្បាស់។ ប៊ូតុងមួយសម្រាប់ confirm ហើយប៊ូតុងមួយទៀតសម្រាប់ថយក្រោយជានិច្ច។ ឆ្វេងស្តាំសម្រាប់ដូរ settings។ ហើយមាន keyboard តូចលើ screen សម្រាប់ឲ្យ player វាយឈ្មោះបានទៀត។
នៅចុងបញ្ចប់ អត្ថបទហ្នឹងឲ្យ prompt វែងមួយ។ Prompt ហ្នឹងធ្វើឲ្យ AI រៀបរាប់រាល់ input និង screen ទាំងអស់សិន។ បន្ទាប់មក វានឹងភ្ជាប់ browser Gamepad API ទៅកាន់ input ដែល game ប្រើស្រាប់។ Gamejam បាន test prompt ហ្នឹងម្តងក្នុង Claude Code ជាមួយ game three.js តូចមួយ។ ពួកគាត់ថា AI ធ្វើការប្រហែលមួយម៉ោង ហើយពួកគាត់មិនបានកែ code ដោយផ្ទាល់ដៃអីបន្តិចសោះ។
សម្រាប់កម្ពុជា
យុវជនខ្មែរយើងច្រើនណាស់ដែលបង្កើត game តូចៗលើ browser ដោយប្រើ AI។ ហើយ controller USB ឬ Bluetooth ធូរថ្លៃក៏ស្រួលរកទិញនៅទីនេះដែរ។ Prompt នេះធ្វើឲ្យ game លេងជាមួយ controller បានតាំងពីដើមដល់ចប់។ អ្នកមិនចាំបាច់រៀនប្រើ Gamepad API ដោយខ្លួនឯងទេ។
កំណត់ចំណាំ
កំណត់សម្គាល់
X article by Gamejam (@ShipOnGamejam on X), 26 Nov 2026, 'How to add real gamepad support to your browser game (and a prompt that does it)', read via the X API on 2026-11-27. The prompt is quoted verbatim from the code block in the article. The test result (about one hour in Claude Code, no hand changes, checked with a simulated controller) is their claim. Gamejam is a site for games made with AI, and the article ends with a link to it. The hero clip is the animated demo from the article. Title, summary and why are in our words.
ប្រភព
បើកប្រភពដើម។
https://x.com/ShipOnGamejam/status/2125978256448864602 (បើកផ្ទាំងថ្មី)
កំណត់សម្គាល់ពីប្រយោគបញ្ជា
រក្សាទុក prompt ជា English។ Run វាក្នុង folder game របស់អ្នកជាមួយ AI coding tool។ ក្រោយកែរួច សាកលេង game ដោយប្រើតែ controller។
ប្រភេទដំបូងលើករណីមួយ គឺជាគោលបំណងចម្បង។ ប្រភេទបន្ទាប់ គឺជាស្លាកបន្ទាប់បន្សំ។