feat: adapt to screen/window size
This commit is contained in:
parent
8046125d71
commit
ce57476a27
1 changed files with 8 additions and 4 deletions
12
index.js
12
index.js
|
@ -8,17 +8,21 @@ let engine = Engine.create({
|
|||
},
|
||||
});
|
||||
|
||||
const width = window.innerWidth > 0 ? window.innerWidth : screen.width;
|
||||
const height = window.innerHeight > 0 ? window.innerHeight : screen.height;
|
||||
console.log('>>> width, height', width, height);
|
||||
|
||||
// create runner
|
||||
let runner = Runner.create();
|
||||
let ground = Bodies.rectangle(400, 610, 810, 60, { isStatic: true });
|
||||
let ground = Bodies.rectangle(width / 2, height - 300, width / 2, 60, { isStatic: true });
|
||||
|
||||
// create a renderer
|
||||
let render = Render.create({
|
||||
element: document.getElementById("canvas"),
|
||||
engine: engine,
|
||||
options: {
|
||||
width: 1600,
|
||||
height: 800,
|
||||
width: width - 18,
|
||||
height: height - 150,
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -52,7 +56,7 @@ function addShape() {
|
|||
// to be continued
|
||||
// let oneShape = Bodies.circle(80, 80, 80);
|
||||
let oneShape = Bodies.polygon(
|
||||
Math.random() * 450 + 1,
|
||||
Math.random() * width / 2 + 12,
|
||||
Math.random() * 450 + 1,
|
||||
Math.random() * 12 + 1,
|
||||
Math.random() * 150 + 100
|
||||
|
|
Loading…
Reference in a new issue