Matter.js 改变颜色 [英] Matter.js change colors
问题描述
我在一个小项目中使用 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
推荐答案
属性有 body.render.fillStyle
、body.render.strokeStyle
和 body.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屋!