Почему тела нарисованы неправильно? - PullRequest
0 голосов
/ 12 октября 2019

У меня проблема с телами в MatterJS. В моем кодовом поле приземляется на невидимую платформу вместо земли. Я запутался с количеством этих параметров объекта. Кто-нибудь знает решение?

var Engine = Matter.Engine;
var Bodies = Matter.Bodies;
var World = Matter.World;
var Body = Matter.Body;

var canvas;
var ctx;

var engine;
var world;
var box;
var floor;

function setup() {
  canvas = document.getElementById("container");
  ctx = canvas.getContext("2d");
  engine = Engine.create();
  world = engine.world;
  box = Bodies.rectangle(50, 50, 100, 100);
  World.add(world, box);
  floor = Bodies.rectangle(0, 750, 1000, 250, { isStatic: true });
  World.add(world, floor);
  Engine.run(engine);
}

function draw() {
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  ctx.fillRect(
    box.position.x,
    box.position.y,
    box.bounds.max.x - box.bounds.min.x,
    box.bounds.max.y - box.bounds.min.y
  );
  ctx.fillRect(
    floor.position.x,
    floor.position.y,
    floor.bounds.max.x - floor.bounds.min.x,
    floor.bounds.max.y - floor.bounds.min.y
  );
  window.requestAnimationFrame(draw);
}

setup();
window.requestAnimationFrame(draw);
...