Jump to content

Game canvas gets wrong resize in DIV


Riddik
 Share

Recommended Posts

Hi,

 

If game is in <body> then the size is correct:
 
 
body.PNG
 
 
But when the game is place to <div> then the size is wrong and there are additional spaces around canvas in both sides
 
div.PNG
 
 
 
How to fix this and remove that space?
 
body and div style:
 
body{        background-color: black;    margin: 0;}#gameContainer{           width: 100%;    height: 100%;    position: absolute;     }
Link to comment
Share on other sites

Probably need more information, but if you are doing position: absolute, you might want to do top: 0px; left: 0px; padding: 0px; too

 

I added this to div style, but the issue still present.

 

Here the canvas style in div:

 

style.PNG

 

You may notice that the canvas has a strange margin parameters.

 

 

 

And here correct canvas in body:

 

body_style.PNG

Link to comment
Share on other sites

Oh, seems I find the solution. Just put this code into resize function:

var gameContainer = document.getElementById(game.parent);gameContainer.style.width = window.innerWidth + "px";gameContainer.style.height = window.innerHeight + "px"; 
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...