Two entities in 1 image?

Hi guys.

I’m thinking on making a fighting game soon, but there’s a problem…

The characters will all have weapons. Now how will that work for collisions? I want to detect character collision against the weapons (not quite character vs character), which may be in different locations (in the sprite animation frame) depending on the move/animation being performed. How could a check a collision vs a certain portion of the other player entity if that portion is changing each frame?

Any ideas?

I’ve always used separate sprites for weapons, and then checked collision against only the weapon sprite. Is that an option, or would it be too hard to separate the weapon from the character?

This post MAY be relevant to your interest, hope it helps you out :slight_smile:

Yeah I would recommend using separate images for each character and their weapons. Then you can detect collisions between the character models themselves and the weapons individually.

Just be careful with how you handle separate BufferedImages, as BufferedImage.createGraphics() can sometimes cause performance hits.

If you run into that issue, convert your images to TYPE_INT_ARGB_PRE and that should help. That should ensure that you won’t have any problems with performance by using multiple sprites for character/weapon entities.

Yeah, I was afraid that would be the solution…

So, maybe a base sprite sheet for each character w/o weapons. I can’t really make the weapon sheet the same size (to have enough room to animate slashes and swings) because then I still don’t have a bounding box. But that would be probably be best anyway because some of the weapons might ginormous, so that will keep all player sprites compact for their own collisions…

So do you guys agree with this? Having a base sprite for the character maybe with no arms or weapons (nvm that’s weird), then have an overlay sheet for weapons and just do pixel-perfect on weapons?