This site requires JavaScript, please enable it in your browser!
Greenfoot back
RedCreeper
RedCreeper wrote ...

2013/9/30

barriers

RedCreeper RedCreeper

2013/9/30

#
I'm making invaders and for the barriers I want to make it so that when a Bullet hits the barrier it takes a chunk out of the barrier, I would like it so that I don't have to use a ton of different pictures. How would I make it so that when the Bullet hits it makes the barrier's image have a transparent spot where it hit? Please help! Thank you.
Gevater_Tod4711 Gevater_Tod4711

2013/9/30

#
If you want to make a transparent rect that's easy. You just have to check where the rect should begin and where it ends and set the pixels at this points to transparency using the setColorAt method. If you want to use circles it's a bit more difficult. Unfortunately you can't just overdraw the image with a transparent color. You need to overdraw the image you want with a color you don't use in your whole image. Then if you have overdrawn the circle you want to 'delete' you need to use two for loops to check the rect where you circle is in. Every pixel that is in the color you used to overdraw the image is changed into a transparent pixel. To see an example you may have a look at my Call of Worms: World at War scenario. I used this method there (I think in the world class and in the textur class).
You need to login to post a reply.