Jump to content

My resize function almost works


Zendrael
 Share

Recommended Posts

Hi!

 

I have built a resize function that scales my CANVAS accordinly to the space available, it shows more or less objects in the scene depending on the horizontal value and scale the canvas to it.

 

It works but right after it is called, the canvas gets back to its default size!!!! VERY ANOYING!

 

The code:

function resizeGame() {    var actualWidth = window.innerWidth;    var actualHeight = window.innerHeight;    GAME.scale.setGameSize( Math.ceil((actualWidth * 160) / actualHeight), 160);            var widthToHeight = GAME.width / GAME.height;    //4 / 3;    var newWidth = window.innerWidth;    var newHeight = window.innerHeight;    var newWidthToHeight = newWidth / newHeight;    if (newWidthToHeight > widthToHeight) {        newWidth = newHeight * widthToHeight;        GAME.renderer.view.style.height = newHeight + 'px';        GAME.renderer.view.style.width = newWidth + 'px';            } else {        newHeight = newWidth / widthToHeight;        GAME.renderer.view.style.width = newWidth + 'px';        GAME.renderer.view.style.height = newHeight + 'px';            }    //atribui o tamanho final    GAME.renderer.view.style.width = newWidth;}

So, my question is: why my game gets back to teh original size (240x160) righr after the page loads???

How to set the style permanent???

 

Thanks! I'm new to phaser...

 

 

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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