michael-Bell Posted April 14, 2014 Share Posted April 14, 2014 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 callgame.camera.follow(player);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 More sharing options...
rich Posted April 15, 2014 Share Posted April 15, 2014 How do you make the player spin? Does it use physics or do you just rotate it? (and if so, when do you rotate it?) Link to comment Share on other sites More sharing options...
michael-Bell Posted April 15, 2014 Author Share Posted April 15, 2014 When you press the up arrow key, it calls the jump() functionfunction 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 More sharing options...
michael-Bell Posted April 21, 2014 Author Share Posted April 21, 2014 How do you make the player spin? Does it use physics or do you just rotate it? (and if so, when do you rotate it?)bump Link to comment Share on other sites More sharing options...
Recommended Posts