I am using the default Render.js and cannot figure out how to create my own canvas and have the game take place in there. I just want to center the canvas in the DOM and stylize around it. Thanks.
Thank you @kroko ! It was a stupid mistake. I had
Its working now!
Render.create({ canvas: document.querySelector('.canvas-physics') });
source: http://brm.io/matter-js/docs/classes/Render.html#properties
What @kroko shows should work (thanks). Also take a look at the Rendering wiki page.
Thank you kroko and liabru. I tried what you suggested, but I am still getting an error:
matter.js:7536 Uncaught TypeError: render.canvas.getContext is not a function at Object.Render.create
This is what I have:
// create a renderer var render = Render.create({ element: document.body, canvas: document.querySelector('#myCanvas'), engine: engine, options: { background:"#2b2b2b", width: 600, height: 960, wireframes: false, showPositions: false, showAxes: false, hasBounds: false, showDebug: false } });
Do not specify element opt, if you specify canvas opt!
element
canvas
Does HTML has
<canvas id="myCanvas"></canvas>
and do you execute JS after DOM has been loaded?
Most helpful comment
Thank you @kroko ! It was a stupid mistake. I had
Its working now!
All 5 comments
source: http://brm.io/matter-js/docs/classes/Render.html#properties
What @kroko shows should work (thanks). Also take a look at the Rendering wiki page.
Thank you kroko and liabru. I tried what you suggested, but I am still getting an error:
This is what I have:
Do not specify
elementopt, if you specifycanvasopt!Does HTML has
and do you execute JS after DOM has been loaded?
Thank you @kroko ! It was a stupid mistake. I had
Its working now!