Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  What is better for animation?  (Read 1361 times)
0 Members and 1 Guest are viewing this topic.
Offline Graziano Mesina

Senior Newbie





« Posted 2006-09-24 15:56:37 »

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
[CODE]
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);
[/CODE]

 Huh Huh

-Montanelli-: Ma lei evadeva quasi sempre, no? <br /><br />-Mesina-: Sì, ho la fortuna di avere i polsi più grossi delle mani...
Offline fletchergames

Senior Member





« Reply #1 - Posted 2006-09-24 16:02:46 »

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.
Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #2 - Posted 2006-09-26 18:29:18 »

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:
1  
2  
3  
4  
5  
6  
  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:
1  
2  
3  
4  
  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
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline kevglass
« League of Dukes »

JGO Kernel


Medals: 54
Projects: 20


Mentally unstable, best avoided.


« Reply #3 - Posted 2006-09-26 18:35:02 »

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

Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #4 - Posted 2006-09-28 03:08:16 »

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?

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
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (84 views)
2013-05-17 21:29:12

alaslipknot (92 views)
2013-05-16 21:24:48

gouessej (123 views)
2013-05-16 00:53:38

gouessej (117 views)
2013-05-16 00:17:58

theagentd (127 views)
2013-05-15 15:01:13

theagentd (114 views)
2013-05-15 15:00:54

StreetDoggy (158 views)
2013-05-14 15:56:26

kutucuk (180 views)
2013-05-12 17:10:36

kutucuk (180 views)
2013-05-12 15:36:09

UnluckyDevil (187 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.097 seconds with 20 queries.