Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Getting the camera to follow the player


Recommended Posts

I'm having a few issue getting a simple demo working. All I want to do is have a player move around a world which is larger than the viewport, centered in the camera.


You can see what I have so far in this example.


I'm not sure what i'm doing wrong, everything looks the same as the camera follow example, but in mine the player gets stuck for a moment when he hits the point where the camera should start following him.


Any ideas where I have gone wrong?

Link to comment
Share on other sites

  • 1 month later...

Ah, my apologies for the bump here, but for posterity (and for me, in case this happens to me again):


The with and height on the game must be the same as the width an height of the tilemap layer ( I know.. that doesn't make sense to me, but there it is).


In other words, your game setup and layer setup lines originally looked like this:


var game = new Phaser.Game(640, 480, Phaser.CANVAS, null, {
layer = game.add.tilemapLayer(0, 0, 720, 720, tiles, map, 0);


And one needs to change the 720,720 to match the Phaser.Game values like so:


layer = game.add.tilemapLayer(0, 0, 640, 480, tiles, map, 0);


Worked for me, at least...

Link to comment
Share on other sites

Also, totally offtopic, but I'd recommend doing this with control schemes:


	player.body.velocity.setTo(0,0);	if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {        	player.body.velocity.x -= 100;        }        if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {        	player.body.velocity.x += 100;        }...snip...

instead of just setting directly. This is an easy way to make pressing left+right at the same time cancel each other out.

Link to comment
Share on other sites


  • Recently Browsing   0 members

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