Jump to content

Phaser resizeChange


damager
 Share

Recommended Posts

Hi(sorry for my English), i've just started using Phaser, but i stucked with one problem. I have a problem with resizeChange of my game. onSizeChange and setResizeCallback just don't work. When i resizing my browser they don't generate signals. I know there is many themes like that but i've seen every of them and didn't find a solution. Please help)

P.S: Phaser 2.9.1. May be trouble in this version of Phaser? In that version even state.callbackContext.resize() was removed.

My typescript code(code for resizeCallback i've took from another theme):

 this.game.scale.setResizeCallback(this.resizeCallback, this);
        this.game.scale.onSizeChange.add(()=>
        {
            let scale_x: number = window.innerWidth / this.game.width;
            let scale_y: number = window.innerHeight / this.game.height;
            this.game.scale.setUserScale(scale_y, scale_y);
            this.game.scale.align(true,true);
            this.game.scale.scaleMode = Phaser.ScaleManager.USER_SCALE;
            this.game.scale.refresh();
            alert("huh");
        }, this)

    
resizeCallback(manager)
    {
        var userRatio = 1;
        if(this.game.device.pixelRatio>1)
        {
            userRatio = this.game.device.pixelRatio * 1;
        }
    
        if(manager.width !== window.innerWidth*userRatio || manager.height !== window.innerHeight*userRatio)
        {
            manager.setGameSize(window.innerWidth*userRatio,window.innerHeight*userRatio);
            manager.setUserScale(1/userRatio, 1/userRatio);
        }
    }

 

Link to comment
Share on other sites

i found solution, but it can be not right one..

i've removed setResizeCallback and replaced onSizeChanged to time.event.loop with checking the changing of window size...But i still hope there is an event(Signal) to detect changing window size.

Link to comment
Share on other sites

Thank you for the answer, but my problem was pretty easier than i thought.

i've just changed the path to function. Somehow it didn't see it;

this.game.scale.setResizeCallback(this.resizeCallBack, this);

That's work:

this.game.scale.setResizeCallback(SimpleGame.prototype.resizeCallBack, this);
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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