I’m creating a 2d single-player adventure game using a 3d tile-based system (yes, a 3d array of tiles), on java2D. But its sooo slooowww… i’m getting 14 frames per second, and this is after changing Image types several times (now i’m using generic Images created by the component’s createImage() and set to equal Images returned by ImageIO from GIFs) because i had been getting udderly ridiculous drawing speeds of 2 or 3 fps with certain BufferedImages. Can anyone please help me speed up the drawing?
Please be more specific.
What exactly are you doing? Are you using translucency? Are you manipulating the pixels directly (through getRaster and such). What jdk version are you using? What os/hardware? Are you using fullscreen? VolatileImages?
yes i’m using translucency, no i’m not manipulating the pixels directly, i use JCreator 2.00 but compile in the command promt on windows xp, no im not using fullscreen. As for image types, here is a sample of some code:
Image myPic;
myPic = (ImageIO.read(new File(“myPic.GIF”)));
myPic= makeTransparent(myPic, new Color(0, 0, 0));
public Image makeTransparent(Image image, final Color tColor){
ImageFilter filter = new RGBImageFilter(){
public int tColorRGB = tColor.getRGB();
public final int filterRGB(int x, int y, int rgb){
if((rgb | 0xFF000000) == tColorRGB){
return 0x00FFFFFF & rgb;
}
else{
return rgb;
}
}
};
ImageProducer iProducer = new FilteredImageSource(image.getSource(), filter);
return Toolkit.getDefaultToolkit().createImage (iProducer);
}
I think this fancy image loading is messing you up… Just use the AWT image loading it will deal with GIf transparency for you and the image will be managed. (accelerated)
ImageIO does not give you accelerated images.
And unless you are using Alpha values other than 0 or 0xFF you are using transparency not translucency. Transparency should be accelerated most of the time, but for accelerated translucency you must set properties to enable it.
I’m not sure what you’re trying to achieve with your code, but I agree with swpalmer: ditch FilteredImageSource.
You can use Toolkit.getImage to load gif images, and by default they will be accelerated if they’re 1-bit transparent or opqaue.
Yet again I’m talking some of Abuse’s code and adding it to the wiki ;D
How to load images with ImageIO (java 1.4 and later I guess):
http://wiki.java.net/bin/view/Games/ImageIO
Please modify and/or add content