Jump to content

Game.Camera.follow Speed Increase


Recommended Posts

I'm teaching myself how to use Phaser, and up until today, I've been using a very rudimentary method for keeping the camera focused on my player ingame. What I had in my update() function was:

game.camera.y = player.y - 200;game.camera.x = player.x - 500;

But recently I discovered the game.camera.follow function. When I call


in the update() function instead of the previous two lines, my game is sped up greatly.
You can see what I mean here:

Hacky Camera follow: http://michaelbell.ca/Phased-Game/camera-debug/hacky/

Game.camera.follow: http://michaelbell.ca/Phased-Game/camera-debug/game-camera-follow/


Arrow keys to move, when you perform a double jump(up arrow, then another up arrow while in the air), he spins, only in the second link, he spins much faster, and the only code I changed is the camera follow code.


Anyways, I would like to know why the game sped up so much when I used the new code, and how can I tell if a line of code is very inefficient

Link to comment
Share on other sites

When you press the up arrow key, it calls the jump() function

function jump(number) {	player.body.velocity.y = -350;	if (number === 2) { // is this a double jump		player.body.velocity.y = -250 - DEX;		player.body.angularVelocity = -200; // start spinning	}}

In the update function, I also run

    if (player.body.blocked.down) {         jumpCount = 0; // reset jump counter        player.body.angularVelocity = 0; // stop spinning        player.angle = 0; // stand up straight    }

to stop the player from spinning when he is touching the ground. You can view the entire code here if you wish.

Link to comment
Share on other sites


  • Recently Browsing   0 members

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