Paul-Andre Posted October 6, 2013 Share Posted October 6, 2013 I've just started with phaser, and I'm wondering how I should center the canvas on the screen. I see that phaser can manage scaling, so I wonder if it could do the centering, or if I should mess with CSS myself, and how exactly. Link to comment Share on other sites More sharing options...
turnA Posted October 6, 2013 Share Posted October 6, 2013 You can use this to center your content: this.game.stage.scale.pageAlignHorizontally = true;this.game.stage.scale.pageAlignVeritcally = true;this.game.stage.scale.refresh();Although I think there's a minor typo in the source code. pageAlignVeritcally or pageAlignVertically? Link to comment Share on other sites More sharing options...
rich Posted October 6, 2013 Share Posted October 6, 2013 Opps, good spot! Fixed in 1.0.7 RestingCoder 1 Link to comment Share on other sites More sharing options...
Paul-Andre Posted October 6, 2013 Author Share Posted October 6, 2013 Thanks! Link to comment Share on other sites More sharing options...
dreta Posted October 12, 2013 Share Posted October 12, 2013 You can center content on a page by setting the horizontal margin to auto. For this to work with canvas you have to set display to block first.canvas { display : block; margin : auto;}This is how pages are centered. You either set the margin for the body or a div that holds the page content. RestingCoder 1 Link to comment Share on other sites More sharing options...
SYNYST3R1 Posted October 14, 2013 Share Posted October 14, 2013 What about centering with webgl? Link to comment Share on other sites More sharing options...
rich Posted October 14, 2013 Share Posted October 14, 2013 WebGL still uses a canvas tag, that is where the content is rendered. It just uses a different context. Link to comment Share on other sites More sharing options...
SYNYST3R1 Posted October 14, 2013 Share Posted October 14, 2013 I tried this.game.stage.scale.pageAlignHorizontally = true;this.game.stage.scale.pageAlignVeritcally = true;this.game.stage.scale.refresh();and it didn't work so I figured it was different for webgl. Not sure how to use it correctly. Link to comment Share on other sites More sharing options...
Stucky Posted May 8, 2014 Share Posted May 8, 2014 I tried this codethis.game.stage.scale.pageAlignHorizontally = true;this.game.stage.scale.pageAlignVeritcally = true;this.game.stage.scale.refresh();with or without "this", but it doesn't work for me as well. Sorry for a noob question, but where do you put it exactly? I put it under function create(), but it doesn't center.I tried to make it fullscreen and put the code under function create(), and it works. I wonder why I can't center the game. Link to comment Share on other sites More sharing options...
Stucky Posted May 8, 2014 Share Posted May 8, 2014 I found the solution. Instead of using the codethis.game.stage.scale.pageAlignHorizontally = true;this.game.stage.scale.pageAlignVertically = true;this.game.stage.scale.refresh();Use this one instead:this.game.scale.pageAlignHorizontally = true;this.game.scale.pageAlignVertically = true;this.game.scale.refresh(); tidelake and Dread Knight 2 Link to comment Share on other sites More sharing options...
Recommended Posts