Henryk Posted March 4, 2015 Share Posted March 4, 2015 Well, I scale my game (1280x720) with setUserScale(scaleFactor, scaleFactor) to the device width (for example: 480x320). When accessing the canvas width it still gives me the original width. How do I get the new size of the canvas? Link to comment Share on other sites More sharing options...
mxmlb Posted March 4, 2015 Share Posted March 4, 2015 By multiplying the game dimension by the game scale ? The fact that your game dimensions are not updated is handy, as all your display objects will keep the correct coordinates. Link to comment Share on other sites More sharing options...
Henryk Posted March 4, 2015 Author Share Posted March 4, 2015 This was not exactly my problem. Basically I just wanted to center the canvas element vertically and no obvious way worked! I now have this work around:// set scaleMode and alignthis.game.scale.scaleMode = Phaser.ScaleManager.USER_SCALE;this.game.scale.compatibility.forceMinimumDocumentHeight = true; // seems to do nothingthis.game.scale.pageAlignHorizontally = true; // seems like I would not even need thisthis.game.scale.pageAlignVeritcally = true; // seems to do nothing// calculate the scale factorscaleFactor = deviceW / origW;// set scalethis.game.scale.setUserScale(scaleFactor, scaleFactor);this.scale.refresh();// calculate the scaled dimensions of the canvascanvasW = origW * scaleFactor;canvasH = origH * scaleFactor;// calculate the Top DistancecanvasTop = (deviceH - canvasH) / 2;// make it a relevant stringcanvasTop = canvasTop.toString() + 'px';// get the after setUserScale() applied style attributesthis.currentStyle = this.game.canvas.getAttribute("style");// add the marginTop to itthis.newStyle = this.currentStyle + 'margin-top: ' + canvasTop;// set the attributethis.game.canvas.setAttribute('style', this.newStyle);I hope my variable names are speaking for themself. Anyway, in my opinion there should be an easier way, shouldn't it? Link to comment Share on other sites More sharing options...
Recommended Posts