我想在我的自定义游戏循环中使用Matter.js,我按照here的说明添加了Engine.update(engine,1000/60,1);在绘制循环中,但什么都没有发生,只是空白屏幕。我需要在某个地方添加tick方法吗?
下面是我的代码:
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);
}
};发布于 2019-04-07 05:18:32
您可能使用了错误的参数。我有一个使用Engine.update的函数,如下所示:
var updateTime = 1000/60;
Matter.Engine.update(engine, [delta=updateTime], [correction=1]);https://stackoverflow.com/questions/32470540
复制相似问题