51 hitBox - JcerelusDev/CanvasGameJs GitHub Wiki

What is hitBox ?

The hitBox method is responsible for attack collision detection.

Depending on the game you are building you may need to attack the enemies or using your attack animation frames to break a wall or a 🚪. This is not an easy task, so this is where

hitBox method is needed.

Info

The method has 3 parameters :

1.- object 1 who performs the atttack

2.- object 2 who receives the attack

3.- gap (type number) , the distance existing between your object 1 sword , foot or hand and the position of object 2.

Example :
function attack(){
  if(hitBox(player,enemy,102)){
   enemy.life -= 2
}
}

The gap is something related to the sword length from object1 body to object 2 body.

Important

It could be the enemy to the player also it's depend on who performs the action.

Example :
function attack(){
  if(hitBox(enemy,player,70)){
    player.life -= 2
}
}