मुख्य सामग्री पर जाएँ
Skillpedia
सामान्य कोडिंग6.4k · #14204

melonjs-input

यह क्या करती है

यह बताती है कि melonJS गेम में कुंजियों को नामित क्रियाओं से कैसे जोड़ें, माउस और टच का जवाब कैसे दें और गेमपैड कैसे सँभालें। यह नियंत्रण बनाने वाले गेम डेवलपर्स के लिए है।

कब इस्तेमाल करें

  • ✓जब डेवलपर चाहे कि मूवमेंट की कुंजियाँ गेमपैड की तरह ही काम करें।
  • ✓जब डेवलपर को जंप या फ़ायर कुंजी हर दबाव पर एक बार चलानी हो।
  • ✓जब डेवलपर की क्लिक वाली वस्तु pointer इनपुट का जवाब न दे।

Skill का लिंक

https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-input/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-input/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“मेरे किरदार को तीर कुंजियों से चलाइए, और स्पेस बार से हर दबाव पर केवल एक बार जंप होने दीजिए।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

यह स्किल AI को कुंजियों को क्रिया के नामों से बाँधने, फिर update लूप में उन क्रियाओं को जाँचने को कहती है, और एक बार वाली क्रियाओं को लॉक करती है ताकि वे हर दबाव पर एक बार चलें।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

Input: keyboard, pointer and gamepad

Keyboard goes through named actions

Do not poll key codes. Bind a key to an action string, then poll the action — this is what lets gamepad and virtual controls map onto the same handling.

import { input } from "melonjs";

input.bindKey(input.KEY.LEFT,  "left");
input.bindKey(input.KEY.RIGHT, "right");
input.bindKey(input.KEY.X,     "jump", true);   // true = locked: one press per keydown

// in update()
if (input.isKeyPressed("left"))  { /* … */ }
if (input.isKeyPressed("jump"))  { /* fires once per press, not per frame */ }

The third argument to bindKey is lock (default false). Without it, isKeyPressed stays true for as long as the key is held — correct for movement, wrong for jump or fire. A locked action stays consumed until the key is released or you call input.unlockKey("jump"). Use input.keyStatus(action) when you want the raw held/not-held state regardless of locking.

A poll can miss a press entirely

isKeyPressed is sampled once per frame, and keyup decrements the key's counter the moment it arrives — locked or not. A press that goes down and up between two frames therefore leaves the counter back at zero and is never seen. At 60fps that is anything under ~16ms: rare from a human finger, routine from a synthetic event, and more likely the slower the frame rate.

For a screen where a missed press is a dead end — a splash, a "press any key", a notice to acknowledge — listen for the event instead, which cannot be missed:

import { event } from "melonjs";

// action is the bound action name, or undefined for an unbound key
const onKey = (action) => { if (action === "menuSelect") continue(); };
event.on(event.KEYDOWN, onKey);      // in onResetEvent
event.off(event.KEYDOWN, onKey);     // in onDestroyEvent — it does not self-remove

KEYDOWN fires for every key, bound or not, so matching on action is what narrows it; it also repeats while the key is held, so guard anything that must happen once. Keep polling for movement and for a menu cursor, where one step per press and a key held across a state change are the things that matter.

The full signature is bindKey(keyCode, action, lock?, preventDefault?); preventDefault defaults to input.preventDefault (itself true). Pass the fourth argument per binding, or change the global default with input.setPreventDefault(false) — assigning input.preventDefault = false does not work, it is a read-only module binding.

Pointer events need isKinematic = false

This is the trap. Renderable.isKinematic defaults to true, and both the broadphase and the pointer dispatcher skip any candidate whose isKinematic is still true. The handler registers successfully and simply never fires.

class Button extends Renderable {
    constructor(x, y, w, h) {
        super(x, y, w, h);
        this.isKinematic = false;               // ← required
    }
    onActivateEvent() {
        input.registerPointerEvent("pointerdown", this, this.onDown.bind(this));
    }
    onDeactivateEvent() {
        input.releasePointerEvent("pointerdown", this);
    }
}

Container, Camera2d, Draggable, DropTarget and the UI* elements set it to false for you, and so does attaching a physics body (Body's constructor sets ancestor.isKinematic = false) — so plain Renderable and Sprite subclasses with no body are the ones that catch people.

Register in onActivateEvent and release in onDeactivateEvent, not in the constructor — pooled objects are reused and would otherwise accumulate handlers.

app.viewport works as a whole-screen region when you want global clicks. Note it is asked before everything else, not as a fallback after nothing matched: the dispatcher appends it to the candidate list and walks that list from the end. So a viewport handler must not return false unless it really means to swallow every pointer event in the game.

The accepted event names are exactly "pointerdown", "pointerup", "pointermove", "pointercancel", "pointerenter", "pointerover", "pointerleave" and "wheel". Anything else — "click", "mousedown", "touchstart" — makes both registerPointerEvent and releasePointerEvent throw invalid event type. melonJS maps the canonical name onto whichever mouse/touch events the device actually supports, so you always register the pointer name.

Which object gets the event

The dispatcher collects the regions nea

अक्सर पूछे जाने वाले सवाल

मेरा जंप कई बार क्यों चलता है?

लॉक किए बिना दबी हुई कुंजी हर फ़्रेम पर दबी गिनी जाती है, इसलिए स्किल एक बार वाली क्रियाओं को लॉक करने की सलाह देती है।

pointer इवेंट मेरी वस्तु तक क्यों नहीं पहुँचते?

स्किल kinematic सेटिंग का ज़िक्र करती है जो चुपचाप pointer इवेंट रोक सकती है।

क्या यह गेमपैड के साथ काम करता है?

हाँ। स्किल कहती है कि गेमपैड उन्हीं क्रिया नामों पर मैप हो सकते हैं।

जानकारी

लेखक का मूल विवरण

Use this skill for keyboard, pointer, mouse, touch and gamepad input in melonJS. Covers the bindKey action indirection, registerPointerEvent on regions, the isKinematic requirement that silently blocks pointer events, which of several overlapping objects receives an event and how to consume it, world vs screen pointer coordinates, and gamepad mapping onto the same actions. Triggers on: input, bindKey, isKeyPressed, KEY, registerPointerEvent, releasePointerEvent, pointerdown, pointerup, pointermove, POINTERMOVE, gamepad, bindGamepad, triggerKeyEvent, virtual gamepad, touch controls, joystick, g

repo: melonjs/melonJS

लोकप्रियता

GitHub स्टार
6.4k
रैंकिंग में स्थान
#14204
लाइसेंस
MIT
अपडेट की गई
2/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

melonjs-20-migration

6.4k

आपके एजेंट को melonJS वर्शन 20 के लिए गेम कोड लिखने में मदद करती है और पुराने वर्शन के आउटडेटेड तरीकों से बचाती है, जैसे ज़रूरी async स्टार्टअप।

कोडिंगसामान्य कोडिंग

melonjs-3d-assets

6.4k

आपके एजेंट को glTF, GLB और OBJ जैसे 3D मॉडल melonJS ब्राउज़र गेम में लोड करने में मदद करती है, scale और lighting विकल्पों के साथ।

कोडिंगसामान्य कोडिंग

melonjs-3d

6.4k

आपके एजेंट को melonJS ब्राउज़र गेम में 3D या 2.5D दृश्य बनाने में मदद करती है, जिसमें कैमरा, मेश, लाइट और गहराई शामिल हैं, इंजन के अपने axis नियमों के साथ।

कोडिंगसामान्य कोडिंग

melonjs-audio

6.4k

आपके एजेंट को melonJS गेम में साउंड इफ़ेक्ट और संगीत जोड़ने में मदद करती है, जिसमें ऑडियो सेटअप, बैकग्राउंड ट्रैक, वॉल्यूम नियंत्रण और स्थानिक ध्वनि शामिल हैं।

कोडिंगसामान्य कोडिंग

मिलती-जुलती skills