Scale mode not applied on ipad
This Issue is about (delete as applicable)
- A bug in the API
If you set the game width and height to 100% when creating Phaser game and after that change the game size, the game on iPad Pro is displayed larger than the screen. My guess it that the EXACT_FIT scale mode is not applied, but I can not debug it, because I don't have a Mac.
What is strange is that the click handlers work on the correct position as if the game was scaled to the screen size, but the screen is drawn in the bigger size. I usually started the example in portrait and it was drawn too big. If I rotated it to landscape and back to portrait, the scale mode applied correctly.
I hope someone with some more understanding how Phaser handles orientation and game size changes would know what happens on orientation change that fixes the scale mode.
I've tried this example on Safari and Chrome on 12.9″ iPad Pro and it failed. I don't have other ios devices to test. It works as expected on Windows and Android, although I could not test it with as high resolution as it is on the iPad.
If you don't change the game size it works as expected.
I've created an example that shows a rectangle with input down and up handlers. setGameSize() keeps the aspect ratio of the canvas and resizes the game to be 1280 wide in portrait and 1920 in landscape. When I load the page on iPad, it is displayed too big and the click handler is registered a bit to the left and up of the rectangle. After rotating the display two times to get back to the same orientation, it works fine.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Test</title>
<style>
body {
width: 100%;
height: 100%;
margin: 0;
}
</style>
<script src="http://examples.phaser.io/_site/phaser/phaser.2.5.0.min.js"></script>
<script>
var game = new Phaser.Game("100", "100", Phaser.AUTO, "", {create: create});
var square;
function create() {
console.log(game.width, game.height);
game.scale.scaleMode = Phaser.ScaleManager.EXACT_FIT;
game.scale.refresh();
setGameSize();
drawSquare();
}
function drawSquare() {
square = new Phaser.Graphics(game);
square.lineStyle(1, '0xffffff', 1);
square.beginFill('0xff0000');
square.drawRect(200, 200, 100, 100);
square.endFill();
square.inputEnabled = true;
square.events.onInputDown.add(down, this);
square.events.onInputUp.add(up, this);
game.stage.addChild(square);
}
function down() {
square.alpha = 0.5;
}
function up() {
square.alpha = 1;
}
function setGameSize() {
var width = window.innerWidth,
height = window.innerHeight;
var xSize;
var ySize;
if (height > width) {
xSize = 1280;
ySize = Math.round(1280 * height / width);
}
else {
xSize = 1920;
ySize = Math.round(1920 * height / width);
}
game.scale.setGameSize(xSize, ySize);
}
</script>
</head>
<body>
</body>
</html>
Thank you for taking the time to open this issue. However, official support for Phaser 2 has now ended as we focus on preparing Phaser 3 for beta release. In a bid to keep the project tidy, and avoid confusion, we are closing all v2 related issues.
This does not mean your issue won't be looked-at. In November 2016 the Phaser CE (Community Edition) project began. The aim of Phaser CE was to allow the community to continue v2 development. Since then it has gained significant traction, with many updates and releases.
If you are still interested in having your issue investigated we strongly recommend testing the latest Phaser CE release. And only if the problem persists, opening an issue on the Phaser CE repo.