quick question about volatile images

If I have an array of 16 elements, each of which is a frame of animation of a ball spinning, and I have this ball spinning and bouncing around the screen in full screen mode, is it better to have it as a normal image or a volatileImage?

I think a better question is “Do I want it accelerated or not?”. I would think you would. The problem with puting it into a volatile image is you loose tranparency. However if you let java accelorate it for you , in an automatic image, you get the speed and the transparency.

What lines of code turn a regular image
image = Toolkit.getDefaultToolkit().getImage(“image.png”);
Into an “automatic” image?

[quote]What lines of code turn a regular image
image = Toolkit.getDefaultToolkit().getImage(“image.png”);
Into an “automatic” image?
[/quote]
You should use toolkit.createImage(), rather than toolkit.getImage().

There are several ways you can obtain automatic images.

  1. Images obtained from toolkit.createImage() are eligable for hardware acceleration.

  2. If you need an image that is eligable for hardware acceleration, and can also be modified, you should use :-

graphicsConfiguration.createCompatibleImage(width,height[,Transparency.BITMASK]).

Images obtained from this method will be eligable for acceleration so long as you never obtain a direct reference to the raster (getRaster()/getAlphaRaster()/etc).

Also, images will only be accelerated if they are opaque, or have a bitmask transparency(Transparency.OPAQUE and Transparency.BITMASK) - full translucency is not supported at this time.

Actually, [opaque and 1-bit transparent] images loaded with Toolkit.getImage() will be accelerated if there’s enough vram.

There’s not much difference between Tookit.getImage and Toolkit.createImage in this sense.

Ok a few questions.

  1. So how do I check if my imags are accelerated?
    2)by full translucency do you mean something like a semi transparent red color?

Im still confused concerning my original question. Could someone please post a bit of code that shows how to create an “automatic” image from an image file “image.png”

  1. currently, there’s no way to find out if the image is accelerated
  2. that’s correct… Check out java.awt.Transparency class for more info.
  3. Use Toolkit.getImage(“image.png”):
    Toolkit.getDefaultToolkit().getImage(“image.png”);
    (don’t forget to use ImageTracker class to make sure the image is fully loaded prior to using it)

Or, alternatively, you can use Swing’s ImageIcon class to load the image:
Image im = new javax.swing.ImageIcon(“image.png”).getImage();
It’ll make sure the image is loaded.

There was another thread with Chet’s explanation of the conditions under which an image gets accelerated.
In short: only opaque and 1-bit transparent images are accelerated, only of there’s enough vram, and only i fyou don’t grab a DataBuffer (or Raster) of the image.
The image gets accelerated after a few copies of this image were made to another accelerated surface (VolatileImage or screen).

When you say one bit transparent do ou mean that a pixel has tobe either completely opaque or completely transparent for the image to be accelerated? I wanted to give my sprites semi transparent shadows, but I gues i will have to make them either completely black or granular.

[quote]When you say one bit transparent do you mean that a pixel has tobe either completely opaque or completely transparent for the image to be accelerated?
[/quote]
Yes, that is what he means. As for the shadows one hack would be a checkerboard pattern of black and transparent pixels.

[quote]Actually, [opaque and 1-bit transparent] images loaded with Toolkit.getImage() will be accelerated if there’s enough vram.

There’s not much difference between Tookit.getImage and Toolkit.createImage in this sense.
[/quote]
The reason I was recommending the use of createImage() over getImage() was solely based on the comments in the java doc with regard to caching <tapping of ctrl+c/ctrl+v>