Matter.js 改变颜色 [英] Matter.js change colors

查看:33
本文介绍了Matter.js 改变颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个小项目中使用 matter.js.

I'm working with matter.js on a small project.

我正在尝试更改画布的背景颜色并为对象添加自定义颜色.

I'm tryin to change the background color of the canvas and add custom colors to objects.

有没有人知道一个教程或者什么样式的东西.js

Does anyone know a tutorial or something for styling matter.js

Matter.js

推荐答案

属性有 body.render.fillStylebody.render.strokeStylebody.render.lineWidth.

您可以将这些传递给 Body.create(options) 或更可能的是,如果您使用的是工厂,例如

You can pass these to Body.create(options) or more likely if you're using a factory e.g.

Bodies.rectangle(0, 0, 100, 100, {
    render: {
         fillStyle: 'red',
         strokeStyle: 'blue',
         lineWidth: 3
    }
});

你也可以使用精灵,见代码

如果需要更多渲染控制,最好克隆Render.js,自定义并通过Engine.create(element, options)作为engine.render.controller传入引擎.

If you need more rendering control, it's best to clone Render.js, customise it and pass it into the engine through Engine.create(element, options) as engine.render.controller.

这篇关于Matter.js 改变颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆