help with images in game
I am trying to make a space game that involves .gif image of the space ship rotating around. While I can get the image to rotate, the transparent parts of the image become black when I do, so the ship becomes a black box with the image in the middle of it floating around. Heres how Im currently rotating the image:
private BufferedImage rotateImage(Image img, int degrees)
{
BufferedImage img2 = new BufferedImage(img.getWidth(null), img.getHeight(null), Image.SCALE_SMOOTH);
Graphics2D img2g = img2.createGraphics();
img2g.rotate(Math.toRadians(degrees), (double)img.getWidth(null)/2, (double)img.getHeight(null)/2);
img2g.drawImage(img, 0, 0, null);
return img2;
}
# 1 Re: help with images in game
If you know which color(s) should be transparent (black?), you might find these useful: Creating A Transparent Background (http://www.ibm.com/developerworks/library/j-begjava/index.html#h2), Make A Color Transparent (http://www.rgagnon.com/javadetails/java-0265.html)and Transparent Pixels (http://forum.java.sun.com/thread.jspa?forumID=54&threadID=360829). Lots of examples: Java Developers Almanac - Images (http://www.exampledepot.com/egs/java.awt.image/pkg.html#Buffered%20Images).
It is not knowledge, but the act of learning, not possession, but the act of getting there which generates the greatest satisfaction...
F. Gauss
dlorde at 2007-11-10 2:15:12 >

# 2 Re: help with images in game
Well I kind of got it to work, but it just has to do so much superfluous crap that its far too slow for what I need it for. Ill probably just end up having to pre-render a bunch of different gifs at every 5 or 10 degree increment and choose the one I want. Its going to be a pain, though, for some 30 different gifs.
# 3 Re: help with images in game
Sounds like you need an efficient sprite animation. Just a suggestion, but if you Google for 'java sprite' you might find something useful.
Any performance problem can be solved by removing a level of indirection...
M. Haertel
dlorde at 2007-11-10 2:17:13 >
