How can a sprite damage an enemy?

Hey there,

I need understand how an animation can damage an enemy, is it possible?

The previous animation causes that the hero to attack, but I can’t understand how can manage it for damage an enemy, how detect collision when the hero attack etc.

I haven’t problem if this functionality is caused by a projectile, but with a sword that is part of the animation I do not understand.

Thanks in advanced.

There are multiple ways to do this. You could use collision objects. Another way would be to manually check rectangles/circles around the player when the player attacks to see if there are any objects overlapping its hitboxes. You would have to have a manager with all of the positions and sizes of entities and their hitboxes.

Then when a collision is detect you can send a message to other entities that there was a collision and the direction/type/damage.

2 Likes

A colleague started working on a beat’em up/fighting game a couple of weeks ago and what worked surprisingly well is to launch very short ranged projectiles (game object with collision component) from the player and in the direction of the attack. Spawn it using factory.create(), animate it using go.animate() and delete it once the go.animate() has finished.

5 Likes

Thanks @Pkeod, is it the best way?

Thanks @britzl, I was thinking about a projectile that can not be seen and that has the effect, is that correct?

Yes, exactly. No visual representation. Just a collision component.

1 Like

Great, thanks a lot @britzl