melonjs-sprites-and-animation
ما الذي تفعله
تشرح المهارة كيفية إنشاء الأجسام المتحركة وإعداد الرسوم المتحركة بالإطارات، واستخدام أطالس الخامات من أدوات الرسم الشائعة. وهي موجهة لمطوّري الألعاب الذين يضعون الشخصيات والأجسام في اللعبة.
متى تستخدمها
- ✓عندما يريد المطوّر أن تشغّل الشخصية حركة الوقوف أو المشي.
- ✓عندما يظهر الجسم المتحرك مزاحًا عن المكان الذي وضعه المطوّر فيه.
- ✓عندما يريد المطوّر استخدام ورقة صور مصدّرة من أداة مثل TexturePacker أو Aseprite.
رابط المهارة
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-sprites-and-animation/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“اجعل شخصية البطل الخاصة بي تشغّل حركة الوقوف من ورقة الصور الخاصة بها، وضعها في الزاوية العلوية اليسرى من الشاشة.”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
تشرح المهارة أن مواضع الأجسام المتحركة تكون في المركز افتراضيًا، وتعرض كيفية إنشاء الأجسام المتحركة من الصور أو مناطق الأطلس، وتضبط رسومًا متحركة مسمّاة من قوائم الإطارات.
المحتوى التقني (ملف 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
الأسئلة الشائعة
لماذا ينزاح جسمي المتحرك بنصف حجمه؟
تقول المهارة إن الأجسام المتحركة تكون في المركز افتراضيًا، فالموضع هو المنتصف وليس الزاوية.
ما الأطلس؟
هو صورة واحدة تحتوي على كثير من صور الأجسام المتحركة، مع ملف بيانات يصف مكان كل واحدة.
كيف أضبط إطارات الحركة؟
تعرض المهارة إضافة رسم متحرك مسمّى بقائمة أرقام الإطارات ومدة بالميلي ثانية.
التفاصيل
الوصف الأصلي من المؤلف
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
التعليقات
- …
المزيد من المهارات من هذا المستودع
melonjs-20-migration
6.4kيساعد وكيلك على كتابة كود لعبة melonJS للإصدار 20 وتجنب الدوال القديمة من الإصدارات السابقة، مثل بدء التشغيل غير المتزامن المطلوب.
melonjs-3d-assets
6.4kيساعد وكيلك على تحميل نماذج ثلاثية الأبعاد مثل glTF وGLB وOBJ في لعبة melonJS للمتصفح، مع خيارات المقياس والإضاءة.
melonjs-3d
6.4kيساعد وكيلك على بناء مشاهد ثلاثية الأبعاد وشبه ثلاثية في melonJS، مع الكاميرات والأضواء والعمق وفق قواعد المحور الخاصة بالمحرك.
melonjs-audio
6.4kيساعد وكيلك على إضافة المؤثرات الصوتية والموسيقى إلى لعبة melonJS، بما في ذلك إعداد الصوت والمقاطع الخلفية والتحكم في الصوت والصوت المكاني.
مهارات مشابهة
diffs
394kيتيح لوكيلك إنتاج فرق تعديلات حقيقي يمكن مشاركته، كرابط عرض أو ملف صورة، بدلاً من ملخص مكتوب يدوياً.
coding-agent
394kيساعد وكيلك على تسليم مهمة برمجة كبيرة إلى Codex أو Claude Code أو OpenCode كعامل في الخلفية، ثم متابعة تقدمها.
gh-issues
394kيساعد وكيلك على إيجاد مشكلات GitHub واختيار ما ستعمل عليه، وفتح طلبات سحب بالإصلاحات، ومتابعة تعليقات المراجعة.