Jump to content

Phaser EXACT_FIT + setGameSize = Camera broken


Phaser
 Share

Recommended Posts

Just a fresh Phaser 2.5 project, ScaleManager.EXACT_FIT and when I use setGameSize to zoom in it works fine and when I use setGameSize to zoom out it works fine... HOWEVER eventually it reaches a point where when you zoom out it starts to off center the entire world so the camera is not following the player... This is inconsistent... what is going on? How to fix?

P.S. this isn't just about zooming, I noticed this started to become a problem with multiple 4k monitors.

Link to comment
Share on other sites

I stripped down my program and put together a sample code to illustrate this inconsistency... perhaps someone can point out the error in my code... press 1 then 2 then 3 then 4.... once you get to 4 you can clearly see the world is no longer centered...

<!doctype html>
<html>

<head>
	<meta charset="UTF-8" />
	<title>hello phaser!</title>
	<style>
		body {
			margin: 0;
			background: #B4D9E7;
			position: fixed;
			width: 100%;
			height: 100%;
		}

	</style>
	<script type="text/javascript" src="js/phaser.min.js"></script>
</head>

<body>
	<script>
		var game = new Phaser.Game("100", "100", Phaser.AUTO, '', {
			preload: preload,
			create: create,
			update: update,
			render: render
		})

		function preload() {
			game.scale.scaleMode = Phaser.ScaleManager.EXACT_FIT;
			game.world.setBounds(-Infinity, -Infinity, Infinity, Infinity);
			game.physics.startSystem(Phaser.Physics.P2JS);
		}


		var key1, key2, key3, key4;

		function pressOne() {
			game.scale.setGameSize(
				1280,
				720);
		}

		function pressTwo() {
			game.scale.setGameSize(
				1920,
				1080);
		}

		function pressThree() {
			game.scale.setGameSize(
				3840,
				2160);
		}

		function pressFour() {
			game.scale.setGameSize(
				8000,
				8000);
		}

		function create() {

			key1 = game.input.keyboard.addKey(Phaser.Keyboard.ONE);
			key1.onDown.add(pressOne, this);

			key2 = game.input.keyboard.addKey(Phaser.Keyboard.TWO);
			key2.onDown.add(pressTwo, this);

			key3 = game.input.keyboard.addKey(Phaser.Keyboard.THREE);
			key3.onDown.add(pressThree, this);

			key4 = game.input.keyboard.addKey(Phaser.Keyboard.FOUR);
			key4.onDown.add(pressFour, this);

			var circle = game.add.graphics(0, 0);
			circle.beginFill(0xF0C8FF);
			circle.drawCircle(0, 0, 100);
			circle.endFill();
			circle.x = game.world.centerX;
			circle.y = game.world.centerY;

			game.physics.p2.enable(circle, false, false);
			circle.body.clearShapes();
			circle.body.addCircle(100 / 2, 0, 0, 0);
			circle.body.shapeChanged();
			game.camera.follow(circle);
		}

		function update() {}

		function render() {}

	</script>
</body>

</html>

 

Link to comment
Share on other sites

  • 2 weeks later...

Since you've gone through the trouble of making the tiniest case where it shows the problem it'd be a shame if you didn't post this as a bug.

Sign up for GitHub if you don't already have an account. Go here: https://github.com/photonstorm/phaser/issues Click the green "New Issue" button. It will pre-fill the issue description box with some instructions. Put the code that shows the issue in here: https://jsfiddle.net/ You might have to play around a bit to get it to load Phaser correctly. Put the link to your jsfiddle in the bug when describing the problem. Submit the issue!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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