FLOSS Manuals

 English |  Español |  Français |  Italiano |  Português |  Русский |  Shqip

Learn JavaScript with Phaser

Polish: Screen Shake when Zapped

Rather than just disappearing we can add an animation to the whole screen to give our game player feedback that something bad has happend. We can do this by shaking the screen.

Check the Code: what we need to know and do

Better death here needs us to alter the function called when player and enemy overlaps. Let's concentrate on animating the enemy, we need to change the sprite animation but also add a delay into the process of restarting the game so we can see the animation play out. So we'll need the following background knowledge;

The code for a minimal example of the Shake Screen when Zapped game polish element is shown here -  https://add-polish-shake-screen.glitch.me/
 

Going over the code:

Have a look at an updated hitHazard function;

playState.hitHazard = function (player, hazard) {
      hazard.kill();
      game.camera.shake(0.05, 500);
};

We just need to add a line about shaking the cameral position of the whole game into the hitHazard function.

Bonus: If you don't like the way everything shakes here then the shake effect can be done only on limited sprites or groups for a demo of that see here. https://glitch.com/edit/#!/add-polish-shake-sprites-only?path=game.js

There has been error in communication with Booktype server. Not sure right now where is the problem.

You should refresh this page.