melonjs-particles-and-trails
它能做什么
它介绍如何在 melonJS 中设置粒子发射器和拖尾,包括瞬间爆发和持续喷发两种效果。适用于添加爆炸或尾焰等视觉效果的游戏开发者。
适用场景
- ✓当开发者想在 melonJS 游戏中添加火花或爆炸效果时。
- ✓当开发者添加了粒子发射器,但屏幕上什么也没有出现时。
- ✓当开发者想在移动对象后方添加运动拖尾时。
技能链接
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-particles-and-trails/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请在玩家撞到墙壁时为我的游戏添加一次火花爆发,并确保它确实能显示出来。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能说明,发射器必须被告知开始发射,方式可以是爆发或持续喷射。它还涵盖速度、寿命和数量等设置。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Particles and trails
An emitter does nothing until you tell it to emit
Adding a ParticleEmitter to the world is not enough. Nothing appears, and
nothing warns you.
const emitter = new ParticleEmitter(x, y, {
image: loader.getImage("spark"),
totalParticles: 60,
speed: 4,
minLife: 200, maxLife: 800,
});
world.addChild(emitter);
emitter.streamParticles(); // continuous — or:
emitter.burstParticles(); // one shot
streamParticles(ms) takes an optional run time; without one it uses the
duration setting, which defaults to Infinity — a stream runs until
stopStream(). burstParticles(n) launches n, or totalParticles.
Without an image, particles are white squares of textureSize pixels (8 by
default), coloured by tint. Every such emitter draws the renderer's one
shared white pixel, stretched, so an emitter per explosion or a reset() on
every tweak costs no texture.
Tuning an effect: the Particle Editor
Settings are easier to find by eye than by reasoning. The
Particle Editor
runs one emitter live, with every setting on a slider, from a preset (fire,
smoke, rain, explosions, 3D bursts and rings…), a built-in texture or a sprite
(sheet) of your own, under a 2D camera or an orbiting 3D one. It writes out the
matching new ParticleEmitter(...) call, listing only what differs from the
defaults, and the same settings as JSON, in the emitter's own units, to load at
run time:
// preloaded with { name: "smoke-fx", type: "json", src: "data/fx/smoke.json" }
const effect = loader.getJSON("smoke-fx");
const emitter = new ParticleEmitter(x, y, {
...effect.settings,
// no `image` for the plain square: `getImage` would give null
...(effect.image ? { image: loader.getImage(effect.image) } : {}),
});
Point a user there when they are tuning numbers by trial and error.
It covers every setting that changes how one emitter looks, but not:
- Layered effects. It shows one emitter at a time. A campfire (flames,
sparks, smoke) or an explosion (flash, debris, smoke) is several emitters
at the same spot: tune each in the editor, then add them side by side,
the one drawn on top last (or with a higher
z). - Trails.
TrailandTrail3dare separate renderables; see below. - Code-only settings.
onComplete,autoDestroyOnComplete,accurateBounds, and aContainerasreferenceSpace(it offers"local"and"world").textureAdditiveis left out:blendModereplaces it. - Changes at run time. Calling
burstParticles()when something happens, or assigningemitter.blendModewhile particles are alive, is game code. Its "moving emitter" option previews the common case: an emitter attached to something that moves.
Sprite-sheet particles
Use framewidth and frameheight (the same names as on Sprite) to divide
image into a regular grid. Each omitted dimension defaults to that of the
image. Frames are numbered from zero left-to-right, then top-to-bottom; only
whole cells count, so partial cells along the right/bottom edges are ignored.
Margins and spacing are not supported.
const explosion = new ParticleEmitter(x, y, {
image: loader.getImage("explosion-sheet"),
framewidth: 32, frameheight: 32,
frames: [0, 1, 2, 3],
minLife: 400, maxLife: 800,
});
world.addChild(explosion);
explosion.burstParticles();
Omit frames to use every cell. Each particle traverses the sequence once
over its own lifetime, with equal time for each entry; repeated indices hold
a frame longer. Existing scale, opacity and rotation still apply. Bounds and
the rotation pivot use one frame's dimensions, rather than the whole sheet.
Set randomFrame: true for debris: a particle chooses one entry at birth and
keeps it until it dies. Different frames share the same image and GPU batch.
Without sheet settings, particles still draw the whole image as before, and
that includes randomFrame on its own: it needs a grid to choose from, so
pair it with framewidth/frameheight or it does nothing.
Note the variety is in SHAPE, not colour. tint belongs to the emitter, so
every particle from one emitter is tinted alike however many frames it picks
between. For a colour that changes over each particle's life, use
tintOverLife (below) rather than drawing one frame per colour.
Frame dimensions must be positive integers that fit inside the image, and an ex
常见问题
为什么我的发射器什么也不显示?
该技能说明,仅仅添加发射器是不够的,还必须调用爆发或持续喷射的方法。
我能使用自己的图片吗?
可以。如果没有图片,粒子就是小的彩色方块。
有用于调整效果的可视化工具吗?
有。该技能提到了 Particle Editor,它可以输出对应的设置代码。
详情
作者的原始描述
Use this skill for particle effects and motion trails in melonJS — ParticleEmitter configuration, burst versus stream emission, the referenceSpace frame of reference introduced in 20.2, 3D particle motion through elevation and minSpread/maxSpread in 20.8, and the Trail renderable. Covers the emitter that silently does nothing until you call an emit method. Triggers on: Trail3d, ribbon, exhaust trail, speed streak, ski track, tyre mark, ribbonNormal, ParticleEmitter, particles, particle editor, tune particles, spawn depth, volume, burstParticles, streamParticles, referenceSpace, ParticleEmitter
repo: melonjs/melonJS
热度
- GitHub 星标
- 6.4k
- 排名
- #14208
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
melonjs-20-migration
6.4k帮你的智能体按 melonJS 20 版本编写游戏代码,避免使用旧版本中已过时的方法,例如必需的异步启动。
melonjs-3d-assets
6.4k帮你的智能体将 glTF、GLB 和 OBJ 等 3D 模型加载到 melonJS 浏览器游戏中,并提供缩放和光照选项。
melonjs-3d
6.4k帮你的智能体在 melonJS 浏览器游戏中构建 3D 或 2.5D 场景,涵盖相机、网格、灯光和深度,并遵循引擎自身的坐标轴规则。
melonjs-audio
6.4k帮你的智能体为 melonJS 游戏添加音效和音乐,包括音频设置、背景音轨、音量控制和空间声音。