我想在我的自定义游戏循环中使用 Matter.js,我按照此处的说明添加了 Engine.update(engine, 1000/60, 1); 在绘图循环中,但没有任何反应,只是空白屏幕。我需要在某处添加刻度方法吗?
这是我的代码:
window.onload = function () {
// Matter.js module aliases
var Engine = Matter.Engine,
World = Matter.World,
Bodies = Matter.Bodies;
// create a Matter.js engine
var engine = Engine.create(document.body);
// create two boxes and a ground
var boxA = Bodies.rectangle(400, 200, 80, 80);
var boxB = Bodies.rectangle(450, 50, 80, 80);
var ground = Bodies.rectangle(400, 610, 810, 60, { isStatic: true });
// add all of the bodies to the world
World.add(engine.world, [boxA, boxB, ground]);
// run the engine
//Engine.run(engine);
draw();
function draw(){
Engine.update(engine, 1000/60, 1);
requestAnimationFrame(draw);
}
};