melonjs-renderables
यह क्या करती है
यह बताती है कि melonJS में अपने गेम वस्तु प्रकार कैसे बनाएँ, उन्हें हाथ से कैसे बनाएँ और उन्हें माउस या टच पर प्रतिक्रिया देने योग्य कैसे बनाएँ। यह कस्टम sprites और वस्तुएँ बनाने वाले गेम डेवलपर्स के लिए है।
कब इस्तेमाल करें
- ✓जब डेवलपर कस्टम वस्तु लिखे जो हिलाने पर गलत जगह बने।
- ✓जब डेवलपर की क्लिक करने योग्य गेम वस्तु क्लिक पर प्रतिक्रिया न दे।
- ✓जब डेवलपर को नियंत्रित करना हो कि कौन सी वस्तुएँ दूसरों के आगे दिखें।
Skill का लिंक
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-renderables/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मेरी कस्टम वस्तु जहाँ मैं उसे हिलाता हूँ वहाँ बनने की बजाय ऊपर बाईं कोने में बनती है। इसे कैसे ठीक करूँ?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
यह स्किल समझाती है कि कस्टम ड्राइंग में वस्तु की अपनी position इस्तेमाल होनी चाहिए, और हाथ से बनी वस्तुओं के लिए anchor को ऊपर बाईं ओर सेट करना होगा। यह क्लिक और ड्रॉ क्रम भी कवर करती है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Renderables, input and effects
Subclassing
Renderable, custom drawing, receiving pointer events, and applying post effects — with the traps that produce silently wrong output rather than an error.
Everything here is a silent failure: the code runs, nothing throws, and the result is wrong. Those are the cases worth memorising, because nothing in the type signatures warns you.
1. A custom draw() must position itself from this.pos
The renderer is not pre-translated to the renderable's position when draw()
is called. Container.draw translates by the container's own pos and then
calls child.preDraw / draw / postDraw; preDraw never translates by the
child's pos. Read this.pos and draw relative to it.
class Marker extends Renderable {
draw(renderer) {
// ✗ draws at the parent container's origin, not at the marker
renderer.fillRect(0, 0, this.width, this.height);
// ✓
renderer.fillRect(this.pos.x, this.pos.y, this.width, this.height);
}
}
The symptom is an object that renders correctly at position (0, 0) and appears stuck at the top-left as soon as you move it.
Zero the anchor in custom-draw renderables. preDraw does not translate to
pos, but it does apply the anchor offset (-width * anchorPoint.x, -height * anchorPoint.y). With the default centred anchor, drawing at
this.pos therefore lands half a size off:
constructor(x, y, w, h) {
super(x, y, w, h);
this.anchorPoint.set(0, 0); // ← or every custom draw is offset by -w/2, -h/2
}
2. isKinematic must be false to receive input or collisions
Renderable.isKinematic defaults to true, which means "physics collision
and input events will not impact this renderable". A kinematic renderable is
skipped by the pointer-event dispatcher entirely.
class Button extends Renderable {
constructor(x, y) {
super(x, y, 100, 40);
this.isKinematic = false; // ← required, or clicks never arrive
input.registerPointerEvent("pointerdown", this, () => { /* … */ });
}
}
The symptom is a handler that is registered, looks correct, and never fires.
Note that Container, Camera2d, Draggable, DropTarget and the UI*
elements set it to false for you, and so does the Body constructor on its
owner (which covers Entity and anything you give a body to) — so a plain
Renderable or Sprite subclass with no body is the case that catches people.
The same flag has a second, less obvious effect: it is also the opt-in to the
world broadphase. The quadtree/octree insert skips any child with
isKinematic === true, so body-less objects you want adapter.queryAABB /
querySphere to find need isKinematic = false as well. The builtin
narrowphase likewise requires both partners to be non-kinematic.
3. Draw order: only addChild(child, z) works
There are three separate traps here and they compound.
world.addChild(sprite, 10); // ✓ the only reliable form
renderable.zdoes not exist. There is nozaccessor anywhere onRenderable(nor onRect/Polygonabove it) — onlydepth, which proxiespos.z, and the container's defaultsortOn: "z"comparator readspos.z. Writingsprite.z = 100creates an inert property that nothing reads. Several shipped examples still containthis.z = Number.POSITIVE_INFINITY; those HUDs draw on top only because they happen to be added last. (Azkey in aSprite/ImageLayersettings object is a different thing and is real — it assignspos.zin the constructor — but trap 2 then overwrites it.)- Setting
depthbeforeaddChildis overwritten. WithautoDepthon (the default),addChildwithout an explicitzassignschild.pos.z = children.lengthafter the push, discarding whatever you set. - Setting
depthafteraddChilddoes not reorder. A"z"sort runs when a child is added (autoSort, deferred to the next tick), not whenpos.zchanges. If you must change it later, callcontainer.sort()yourself, or usemoveToTop/moveUp/moveDown/moveToBottom, which reorder the children themselves. (An"x"/"y"sort is different: see below.)
Sorting on "y" (or "x"), and sortOffset
A container with sortOn = "y" draws its children from the smallest pos.y to
the largest, so whatever is lower on screen covers what is above it (top-d
अक्सर पूछे जाने वाले सवाल
मेरी कस्टम वस्तु कोने से क्यों चिपकी रहती है?
स्किल कहती है कि कस्टम draw मेथड को वस्तु की position वैल्यू ही इस्तेमाल करनी चाहिए।
मेरा क्लिक दर्ज क्यों नहीं होता?
स्किल इनपुट नियमों का ज़िक्र करती है जो कुछ वस्तुओं पर चुपचाप pointer इवेंट रोक सकते हैं।
क्या ये त्रुटियाँ दिखाई जाती हैं?
स्किल कहती है कि ये समस्याएँ चुपचाप विफल होती हैं, इसलिए कोड बिना किसी त्रुटि संदेश के चलता है।
जानकारी
लेखक का मूल विवरण
Use this skill when subclassing Renderable, writing a custom draw() method, handling pointer or click events on game objects, applying post effects and shaders, or controlling draw order. Covers the pos-relative draw contract, isKinematic and input, addPostEffect vs the deprecated shader property, and z-ordering. Triggers on: Tween, easing, animate, Renderable, extends Renderable, draw(, update(, isKinematic, pointerEvent, registerPointerEvent, onClick, addPostEffect, removePostEffect, ShaderEffect, addChild, z-order, anchorPoint, floating.
repo: melonjs/melonJS
लोकप्रियता
- GitHub स्टार
- 6.4k
- रैंकिंग में स्थान
- #14212
- लाइसेंस
- MIT
- अपडेट की गई
- 2/11/2026
कमेंट
- …
इस 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
diffs
394kयह आपके एजेंट को बदलावों का असली diff बनाने देती है, जिसे व्यूअर लिंक या इमेज फ़ाइल के रूप में साझा किया जा सकता है, हाथ से लिखे सारांश के बजाय।
coding-agent
394kयह आपके एजेंट को बड़े कोडिंग काम Codex, Claude Code या OpenCode को बैकग्राउंड वर्कर के रूप में सौंपने, फिर उसकी प्रगति जांचने में मदद करती है।
gh-issues
394kयह आपके एजेंट को GitHub issues खोजने, उनमें से काम करने लायक चुनने, और सुधार के साथ pull requests खोलने में मदद करती है, जिसमें समीक्षा टिप्पणियों का फ़ॉलो-अप भी शामिल है।