One thing you may have noticed while moving our hero around the map is that no matter where our hero goes, he always faces the same direction (downwards). While this behavior was widely accepted in the 1980s, the same cannot be said for today's games, even for mobile games. We will now address this in the following section.
As the title says, there are two new things our hero must be able to do. The first one is walking, which will involve animation. The second one is facing the right direction, which will involve using more features of our sprite sheet.
Since our Character
class contains everything related to our hero, we will open the character.js
file and add a new function named turnTowards
to the self
variable. Since our constructor function returns the self
variable, every single character in our game will now have a turnTowards
function, hence making it accessible to the outside world.
The character...