What is better for animation?

Hi, I would create an animation with some frames for my game entities.

Is better to create

an Array of images
or
a single image that will contain all frames and then call methods


g.setClip((int)x,(int)y,image.getWidth(null) / numFrames,image.getHeight(null));         
g.drawImage(image,(int)x - frameCorrente * image.getWidth(null) / numFrames,(int)y,null); 

??? ???

An array of images is probably better because getting a part of the image is generally slower than getting the whole image. Also, it may make it easier for the JVM to determine what images to accellerate.

In some cases it’s better to use a single larger image for your sprites.
It will more likely result in less overhead if this image is to be cached
in vram.

Some hw configurations only allow power of two textures, so
for example your 24x35 sprite will have to be placed into a 32x64 texture.
So if you have tons of textures like that your overhead will be
significant. But if you place all of them into a 512x512 texture,
it could be reduced.

Also, having your sptires in a single image may help with performance
as it requires less context switching for the native pipeline.
Many images:


  copy image 1 into texture 1
  copy image 2 into texture 2
  set texture 1
  render texture 1 at coord1
  set texture 2 
  render texture 2 at coord2

Single image:


  copy image into texture
  set texture
  render texture at coord1
  render texture at coord2

And since setting a new texture is an expensive context switching
operaion (at least, for Direct3D), the second way is typically faster.

For software-only rendering it doesn’t make that much
of a difference.

Thanks,
Dmitri

Interesting, it’s always been the other way round in benchmarks, see the discussion here:

http://www.java-gaming.org/forums/index.php?topic=13768.0

and bench mark here:

http://woogley.net/misc/Clipping/

Generally storing lots of little images in Java2D has been faster. However, with the new opengl pipeline it makes sense in my head that sprite sheets should be efficient.

EDIT: Is there any chance that a sub-image in the new pipeline is just a reference to the old image with different texture coordiantes?

Kev

[quote]Is there any chance that a sub-image in the new pipeline is just a reference to the old image with different texture coordiantes?
[/quote]
If by “sub-image” you mean doing a drawImage of a region of larger image, then yes, in
opengl and d3d pipelines it’s just a tweaking of the teture coordinates of
the same texture.

In other pipelnes it’s pretty much the same thing - just different source
coordinates of corresponding blit operation (srcx,srcy,w,h) instead of 0,0,w,h -
the exact same routine is used as with copying from smaller image.
There’s a bit of extra logic to figure out that this is not a scale (if src/dst width/height
are different or not).

Dmitri