How do you 'damage' an image in game?

BlitzMax Forums/BlitzMax Programming/How do you 'damage' an image in game?

WERDNA(Posted 2010) [#1]
If anyone could answer this, I'd like to know how you could damage\fracture\decimate
an image in game.

What I need this for, is for a space shooter I'm working on. When an enemy
ship is thoroughly damaged, I want the image to be pockmarked, and have a
few holes in it. I 'could' do this by including it in the enemy animation, or including
a separate image of the 'damaged' enemy, but I'm pretty darn sure there is an
easier way to do this.

Is there some kind of pixmap I could create, that's all the pockmarks, holes, etc
that I'd want to be on the enemy, and I would just shape the pixmap to fit over
the enemy image some how?

Or what could I really do?

If someone could help me out on this, that would be great!


Thanks in advance!


Jaydubeww(Posted 2010) [#2]
Maybe create a-mostly-alpha-image strip with a progressive damage then draw it over your current one. Although, drawing it twice will probably bog it down a bit...maybe create a pixmap of all the stages of damage before the actual game plays.


WERDNA(Posted 2010) [#3]
But how do I 'fit' that image over an existing enemy image?

How do I cut out an enemy shaped chunk of it, and ONLY draw that bit, and not the
rest of the pixmap?


Jesse(Posted 2010) [#4]
it is very common to use an animation sequence with the the image in it's progressive condition and display accordingly. An alternative such as displaying multiple images(such as parts of the image next to each other to make the actual image) is also common for displaying animated images and for replacing with images that display damaged. If you ever used LoadAnimImage to show animation you should have an idea of what I am talking about as the animation frames don't necessarily have to be used to display animation. you can have a png in your HD of a ship, load it up in forty different pieces then display them next to each other as to display the whole image. if you want to show damage just replace the old part of the image with another small image showing damage and you are done.

Last edited 2010


WERDNA(Posted 2010) [#5]
Thanks Jesse, that should help out!

Option 2 is too much trouble to implement.

Option 1 is a bit better, and I seem to remember doing something like that for my
Dragon Spirit game.


Still, I'd like some kind of pixmap I could lay over the images. Or some kind of filter I
could run the images through.

If anyone knows how to do either of those, that would help tremendously.


Jesse(Posted 2010) [#6]
I could do that for you but I don't know how efficient that can be for your game as drawing to pixmaps is kind of slow. if it's a fast action, many bullets shmup that you want it for then I don't recommend it. You can do what John Wesley said. You just display an image on top of another image. The top image just contains the damage and everything else is transparent. When you display them, all you are going to see is a ship with the damage area. the top image(damage) can be the size of the original image so you don't have to worry about repositioning it relative to the image in the back. if you make the top image just the size of the damage you are going to have to worry about the positioning of the top image relative to the bottom image so that it always displays in the correct position. the advantage of the second method is that if the top image is smaller it is going to be a bit faster to display.
I don't know if you have seen how some of this crazy kids recently been putting stickers in the cars that look like bullet holes. it'll be something like that but more convincing.

Last edited 2010


WERDNA(Posted 2010) [#7]
Thanks Jesse!

I'll go ahead and give John Wesley's idea a shot, and see how it works.


Thanks everyone!


zambani(Posted 2010) [#8]
Depending on how big your images are, how many ships there are and the frequency of which you expect the damage to change, you can write the damage on top of the image of the ship. This way you end up with only a single image to render each frame. If most ships spend most of their time not going through the various damage phases then this method might be better because the damage can be different each time you write it to the image of the ship.
Obviously this method is more involved than the others but I figured you might want to know about it.


WERDNA(Posted 2010) [#9]
Thanks zambani. That should help out ;)


Jesse(Posted 2010) [#10]
A little bit of topic
have you ever visited the SHMUP-DEV website there is a lot of information in there about SHMUPS if you are interested. There is not much action there anymore as the original owner abandoned it and no one has been able to take over the website as it was or is for grabs. Anyway, there is a bunch of information there that you might find useful for your game.


slenkar(Posted 2010) [#11]
why dont you get an image with bullet-holes/cracks and draw that over the spaceship image?
no pixmaps involved


Jesse(Posted 2010) [#12]
that was mentioned already.


Robert Cummings(Posted 2010) [#13]
Drawing to a pixmap isn't really that slow, but locking it and then uploading it to the card again would be quite slow.

Designing around it is really the answer here. If it has a lot of unique frames it is probably better to do it with 3 sets of animations.

one for normal, one for medium damage and one for heavy damage. You can always add more fire or smoke particles for the in between.


Foppy(Posted 2010) [#14]
In my Wizard Battle game, when an arrow hits a creature the arrow would be "linked" to the creature so that its position relative to the creature is then updated each frame to remain the same. This is basically the "draw bullet hole over spaceship" approach, but using individual bullet holes, implemented as types. Of course when the spaceship is deleted you would have to delete the bullet holes from memory too. (Which is easily done if the linked-list of bullet holes is accessible from the spaceship, for instance through a field named "firstBulletHole". Each bullet hole type would have a field "nextBulletHole" so a linked-list can be created.)


WERDNA(Posted 2010) [#15]
@Foppy
I'm already doing something like that with attachable weaponry ;)
So I can do that pretty easily, it's just figuring out what approach works for the 'damage'.

However I think drawing individual bullet holes\pock marks might be the best way to
go! That would be easy to implement, plus easy to modify so different things can get
damaged in different ways.

As usual Foppy, you're awesome :)