Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed with documentation code... #972

Closed
jyeann opened this issue Feb 8, 2021 · 6 comments
Closed

failed with documentation code... #972

jyeann opened this issue Feb 8, 2021 · 6 comments

Comments

@jyeann
Copy link

jyeann commented Feb 8, 2021

1st time testing here and tried testing out the demo code in getting start, but it kept showing
matter-js: Render.create: options.element was undefined, render.canvas was created but not appended warn

`

<title>Document</title> <script src="./matter-js-0.16.1/build/matter.js"></script> <script> var Engine = Matter.Engine, Render = Matter.Render, World = Matter.World, Bodies = Matter.Bodies;
  // create an engine
  var engine = Engine.create();

  // create a renderer
  var render = Render.create({
    element: document.body,
    engine: engine,
  });

  // 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);

  // run the renderer
  Render.run(render);
</script>
`
@michael-garofalo
Copy link

michael-garofalo commented Feb 15, 2021

Where did you see this documentation?

It looks similar to this...
https://github.com/liabru/matter-js/wiki/Getting-started
...and that works for me, because I used a slightly modified version to help troubleshoot an issue here...
#256 (comment)

matterjs-comparison

It looks like there's an extra comma. Maybe that's a problem?

@francoispeyret
Copy link

@michael-garofalo your remark seems to be the right one

@jyeann
Copy link
Author

jyeann commented Mar 1, 2021

@liabru yes, is the exact getting started code.

tried, but still empty when load browser

tried you #256 (comment) code. still blank browser

@michael-garofalo
Copy link

michael-garofalo commented Mar 1, 2021

tried you #256 (comment) code. still blank browser

Usually, when something like this happens, I open up the developer tools in the browser. Which browser are you using? Typically, there's a console log message that says what's wrong.

The HTML, in issue #256, is not enough. It needs the matter.min.js file too.

<script src="matter.min.js"></script>


I just tested the code and I was like... WTF?! It's blank. 😄

But, upon closer inspection, the page wasn't blank. There was a scrollbar. I was able to scroll the page and then see the demo at the bottom. I don't remember it doing that before. The problem is this...

     <div style="width:100%; height: 100%;">
     </div>

I just removed that part and it seems to be working normally.

@jyeann
Copy link
Author

jyeann commented Mar 2, 2021 via email

@liabru liabru closed this as completed Mar 3, 2021
@bohemian916
Copy link

I also faced the same error.
It was because I loaded the script in the head section.
Instead, I load in the body section, and no error appeared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants