melonjs-sprites-and-animation
यह क्या करती है
यह बताती है कि sprites कैसे बनाएँ, फ़्रेम एनिमेशन कैसे सेट करें, और आम sprite टूल के texture atlas कैसे इस्तेमाल करें। यह गेम में किरदार और वस्तुएँ रखने वाले गेम डेवलपर्स के लिए है।
कब इस्तेमाल करें
- ✓जब डेवलपर चाहे कि किरदार idle या चलने वाला एनिमेशन चलाए।
- ✓जब डेवलपर का sprite उस जगह से खिसका दिखे जहाँ उसने उसे रखा था।
- ✓जब डेवलपर TexturePacker या Aseprite जैसे टूल से एक्सपोर्ट किया sprite sheet इस्तेमाल करना चाहे।
Skill का लिंक
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-sprites-and-animation/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मेरे हीरो sprite को उसकी sprite sheet से idle एनिमेशन चलाने दीजिए, और उसे स्क्रीन के ऊपर बाईं ओर रखिए।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
यह स्किल समझाती है कि sprite की position डिफ़ॉल्ट रूप से केंद्र होती है, दिखाती है कि इमेज या atlas क्षेत्र से sprites कैसे बनाएँ, और फ़्रेम सूची से नाम वाले एनिमेशन सेट करती है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Sprites, animation and atlases
Creating sprites from images or atlases, driving frame animation, and the positioning trap that catches almost everyone.
pos is the centre, not the top-left
Renderable.anchorPoint defaults to (0.5, 0.5), so a sprite's pos is its
centre. Container forces (0, 0) instead, which is why containers and
sprites appear to disagree.
// a 64×64 sprite at (100, 100) covers 68..132, not 100..164
const s = new Sprite(100, 100, { image: "hero", framewidth: 64, frameheight: 64 });
s.anchorPoint.set(0, 0); // switch to top-left positioning if you prefer
Writing top-left maths against the centred default puts everything half a sprite off, with no error. It is the most common source of "close but subtly wrong" placement.
Constructing a sprite
From a plain image:
const hero = new Sprite(x, y, {
image: "hero", // preloaded asset name
framewidth: 32,
frameheight: 32,
});
From a texture atlas region:
const atlas = new TextureAtlas(loader.getJSON("sprites"), loader.getImage("sprites"));
const coin = new Sprite(x, y, { image: atlas, region: "coin_01.png" });
framewidth / frameheight define the animation grid on a sheet. Omit them and
the whole image is one frame.
Animation
hero.addAnimation("idle", [0, 1, 2, 3], 100); // frames, ms per frame
hero.addAnimation("walk", [4, 5, 6, 7]);
hero.addAnimation("die", [8, 9], 150);
hero.setCurrentAnimation("walk");
hero.setCurrentAnimation("die", "idle"); // chain to idle when it ends
hero.setCurrentAnimation("die", { loop: false }); // play once, hold the last frame
hero.setCurrentAnimation("die", { loop: false, onComplete: fn }); // …and call fn when it does
hero.setCurrentAnimation("use", { next: "idle", onComplete: fn }); // call fn, then chain to idle
hero.setCurrentAnimation("run", { onFrame: (frame) => { // each frame playback reaches
if (frame === 3 || frame === 8) footstep();
} });
if (hero.isCurrentAnimation("walk")) { /* … */ }
Frame indices are into the framewidth/frameheight grid. With an atlas, use
atlas.getAnimationSettings([regionNames]) and spread it into the Sprite
settings, or atlas.createAnimationFromName([regionNames]), which returns a
ready-made Sprite. On a fixed-cell spritesheet only numeric indices are
accepted — passing region names throws.
The second argument to setCurrentAnimation is polymorphic. A string chains
to that animation when this one ends. An options object takes
{ loop, next, speed, onComplete, onFrame }, and only an explicit loop: false
stops the looping. A bare function is the legacy form: it fires at every cycle end,
and only holds the last frame if it returns false. Omit the argument entirely
and the animation loops forever.
onFrame(frame) is called with frame 0 when the animation starts, then with each
frame playback reaches, so a footstep or a hit lands on its frame without polling
getCurrentAnimationFrame(). A long tick reports every frame it goes past. It is
not called for a frame set with setAnimationFrame, nor for the frame 0 a
play-once animation would wrap to. Keep the callback in a field when you call
setCurrentAnimation every frame: re-selecting keeps the first one anyway.
With both next and onComplete, the callback runs first and the chained
animation starts with none of its own, so a one-off action (a pickup, an
attack) needs no manual switch back to idle.
Re-selecting the animation that is already current is a no-op, so calling
setCurrentAnimation every frame is safe, and an isCurrentAnimation check
around it adds nothing. An unknown id throws.
Texture atlases
TextureAtlas reads several formats:
| source | how |
|---|---|
| TexturePacker / Free Texture Packer JSON | new TextureAtlas(loader.getJSON(name), loader.getImage(name)) |
| Aseprite JSON export | same as TexturePacker — the format is detected from meta.app |
Aseprite .aseprite / .ase binary |
loader type "aseprite", which stores the composited image and a JSON sidecar under the one asset name |
| ShoeBox | JSON export using the melonJS exporter settings file; same call as TexturePacker |
| fixed-cell spritesheet | new TextureAtlas({ framewidth, frameheight, anchorPoint }, loader.getImage(name)) |
| multi-page | pass an array of atlas JSON objects as the first argument |
Helpers: `createSpriteFromName(nam
अक्सर पूछे जाने वाले सवाल
मेरा sprite अपने आकार के आधे के बराबर क्यों खिसका है?
स्किल कहती है कि sprites डिफ़ॉल्ट रूप से केंद्रित होते हैं, इसलिए position कोना नहीं बल्कि बीच है।
atlas क्या है?
यह एक ही इमेज है जिसमें कई sprite चित्र होते हैं, और एक डेटा फ़ाइल बताती है कि हर एक कहाँ है।
एनिमेशन फ़्रेम कैसे सेट करूँ?
स्किल फ़्रेम नंबरों की सूची और मिलीसेकंड में समय के साथ एक नाम वाला एनिमेशन जोड़ना दिखाती है।
जानकारी
लेखक का मूल विवरण
Use this skill when creating sprites, playing frame animations, or working with texture atlases in melonJS. Covers Sprite construction from a plain image or an atlas region, addAnimation/setCurrentAnimation, TextureAtlas for TexturePacker/ShoeBox/Aseprite, tint, flip, NineSliceSprite, and the centred anchorPoint that offsets naive positioning. Triggers on: Sprite, new Sprite, addAnimation, setCurrentAnimation, isCurrentAnimation, TextureAtlas, TexturePacker, Aseprite, ShoeBox, atlas, region, framewidth, frameheight, tint, flipX, flipY, NineSliceSprite, animation.
repo: melonjs/melonJS
लोकप्रियता
- GitHub स्टार
- 6.4k
- रैंकिंग में स्थान
- #14215
- लाइसेंस
- 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 खोलने में मदद करती है, जिसमें समीक्षा टिप्पणियों का फ़ॉलो-अप भी शामिल है।