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

Login
W
WOD1 posted 3 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?

0
XxCFxX posted 4 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?

0
XanderM posted 4 years ago

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

1

Providing the lift to launch your development career

© 2026 Chris Courses. All rights reserved.