matterjs
它能做什么
这个技能帮助智能体设置 Matter.js,这是一个用于浏览器的二维物理库,并附带可运行的入门场景。适合希望在页面上实现下落物体、拖动互动或其他物理效果的网页开发者。
适用场景
- ✓当你希望网页上的物体通过简单的物理引擎下落、弹跳或相互碰撞时。
- ✓当你希望访客在画布场景中用鼠标拖动物体时。
- ✓当你需要在单页应用中正确清理物理场景时。
技能链接
https://github.com/MengTo/Skills/blob/main/agent-skills/web-design/matterjs/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“你能帮我在网页中加入一个下落方块的物理场景,并让人们可以用鼠标拖动吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会创建引擎、渲染器和运行器,在世界中添加地面和一些形状,如果你需要,还会加入鼠标控制。它还会说明页面切换时如何关闭该场景。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Matter.js Skill
Workflow
- Confirm environment (plain HTML, React, or canvas-only) and rendering approach (Matter.Render for debug vs custom renderer).
- Provide a minimal Engine/World/Render/Runner setup and add bodies.
- Add interactions (mouse constraint) or constraints only if requested.
- Share cleanup steps for SPA or teardown scenarios.
Minimal setup
<script>
const { Engine, Render, Runner, Bodies, Composite } = Matter;
const engine = Engine.create();
const render = Render.create({
element: document.body,
engine: engine,
options: {
width: 800,
height: 600,
wireframes: false
}
});
const runner = Runner.create();
Runner.run(runner, engine);
Render.run(render);
const ground = Bodies.rectangle(400, 610, 810, 60, { isStatic: true });
const box = Bodies.rectangle(400, 200, 80, 80);
Composite.add(engine.world, [ground, box]);
</script>
Common patterns
- Use
Composite.add(engine.world, [...])to add bodies to the world. - Use
Render.create({ element, engine })to create a canvas automatically, or pass acanvasyou create yourself. - Set
render.options.wireframes = falsefor solid rendering. - Use
Runner.run(runner, engine)for a simple loop, or callEngine.updatein your own loop if you need custom timing.
Mouse interaction (optional)
const { Mouse, MouseConstraint } = Matter;
const mouse = Mouse.create(render.canvas);
const mouseConstraint = MouseConstraint.create(engine, { mouse });
Composite.add(engine.world, mouseConstraint);
render.mouse = mouse;
Cleanup checklist (SPA)
- Stop the runner with
Runner.stop(runner). - Remove the render canvas from the DOM.
- Clear engine and world if needed.
Questions to ask when specs are missing
- What viewport size and scaling should the canvas use?
- Are we using Matter.Render or a custom renderer?
- Do you want mouse/touch drag interaction?
- Should the simulation loop be paused when offscreen?
常见问题
使用它需要懂物理学吗?
不需要。该技能提供一个最小可用的设置,你可以逐步修改。
它能和 React 一起使用吗?
可以。该技能涵盖纯 HTML、React 以及仅使用画布的方式,并会先询问你使用哪一种。
如果我没有要求,它会添加其他内容吗?
不会。鼠标交互和约束只有在你要求时才会添加。
详情
作者的原始描述
Use when implementing 2D physics interactions with Matter.js, including Engine/World setup, Render/Runner configuration, adding bodies and constraints, and scroll/interaction-friendly canvas scenes.
repo: MengTo/Skills
热度
- GitHub 星标
- 7.2k
- 排名
- #13449
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …
同一仓库的更多技能
3d-cloth-material
7.2k帮你的智能体在 Three.js 中制作逼真的编织织物,包括纱线编织纹理、柔和光泽、自然褶皱、下摆和缝线。
3d-falling-leaves
7.2k帮你的智能体在 3D 场景中添加逼真的飘落树叶,树叶会翻滚、随风飘动,并在镜头移动时循环利用。
3d-four-seasons
7.2k帮你的智能体为 3D 场景添加春夏秋冬四季效果,无需重建场景即可改变植被、光线、天空和积雪。
3d-high-poly-models
7.2k帮你的智能体构建形状平滑、边缘可信的精细 3D 模型,然后制作在网页上运行流畅的轻量版本。