Premium Features

Download Video

Attacks

Attacks in a game like this require we create what I call an "attack box." Basically, this is a small rectangle that covers the area in which our attack should reach. It should only be activated when we press down on a key, and eventually, it should only register during a specific frame within an animation.

Here we'll add a basic version of attack functionality using just rectangles.

Comments

Want to participate?

Create a free Chris Courses account to begin

W
WOD1 posted 4 years ago

If I wanted to make a kick function (I'm having a friend do sprite animation) would I just set the box at a lower position? If so could I copy the code and modify the keydown and position functions?

XxCFxX's profile photo
XxCFxX posted 5 years ago

whenever I attack with the enemy, the attack box shows until it touches the player.

Should I change the arrow down code to enemy.attack() ? or should I leave it to enemy.isAttacking = true?

XanderM's profile photo
XanderM posted 5 years ago

I think its better to use the attack() because the same for player 1