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 (408)
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  
  Performance of Pre-Assembled Sprites vs. Run-Time Assembly  (Read 1675 times)
0 Members and 1 Guest are viewing this topic.
Offline Oskuro

JGO Coder


Medals: 16


Coding in Style


« Posted 2012-09-10 18:20:05 »

In my current project I need to have sprites subdivided into modular pieces to allow for variations. For example, certain monster categories can have different heads, yet the same body, or, more important, players can switch weapons and armor around, and these changes need show up on the player sprite.

Internally I'm handling the drawing of pixels manually, I extract the byte buffer form the application context and operate on it directly (as a single index byte array I dump data into using System.arraycopy loops).

My question is, of the following options, what is, performance wise, more adequate:

  a) Keep the pieces separate and assemble them each frame.
  b) Pre-generate all possible combinations at level load.

I haven't done benchmarking yet, but my guess is that a hybrid method would be best. Pre-generate monster sprites for a limited number of random variations (Say in each individual game execution there are only 5 variations per monster type, even if the available pieces could yield hundreds of combinations), and do the player character at run-time so all possible combinations are always available.

I've observed that sprite sheets for some games (Like old Zelda games) actually have all possible sprites pre-generated for the player. Then again, their possible combinations are simpler.


In any case, these seems like an issue of memory capacity (pre-generation) vs processor capacity (run-time). Are there any quirks or features of the JVM I need to know about that might tip the decision towards one or the other?


Note: No, I will not use higher order Java structures or library wrappers for graphics. Not for this project at least. On one hand I want to practice graphics management at as low a level as possible, and on the other, portability to C++ is one of my requirements, so the less dependencies, the better.


Edit: Typos

Online sproingie
« Reply #1 - Posted 2012-09-10 19:56:12 »

c) When a new combination is needed, assemble it, render it to a new image (or set of images, if you're dealing with animation), and cache it in another spritesheet.
Offline delt0r

JGO Coder


Medals: 19


Computers can do that?


« Reply #2 - Posted 2012-09-10 20:13:52 »

I assemble on the fly. That is a "unit" is a set of sprites that are rendered (set of quads). Since i am no where near fill rate limited and it gives flexablity with relative movements, i didn't see the point of the complexity of assembling new sprites. 

I have no special talents. I am only passionately curious.--Albert Einstein
Games published by our own members! Check 'em out!
Try the Free Demo of Titan Attacks
Offline princec
« League of Dukes »

JGO Kernel


Medals: 196
Projects: 3


Eh? Who? What? ... Me?


« Reply #3 - Posted 2012-09-10 21:39:58 »

Assemble on the fly.

Cas Smiley

Offline Oskuro

JGO Coder


Medals: 16


Coding in Style


« Reply #4 - Posted 2012-09-11 00:07:53 »

The problem I see is when a sprite needs to be quickly and arbitrarily updated on the fly (Again, I need to benchmark this, I'm just conceptualizing at this stage. For the sake of discussion, let's assume I'm trying to run this on a Blackberry device, and have very limited resources.)

Example, if a player character switches weapons, or gets the weapon (or its head) blown off.

Or, when in multiplayer a client gets an update with the info on nearby creatures and their structure (Say another players burst into the room being chased by an eclectic group of monsters, each sporting a different party hat).


In general I feel uncomfortable making several passes over the same pixels as I draw each piece on top of the previous one.

Offline princec
« League of Dukes »

JGO Kernel


Medals: 196
Projects: 3


Eh? Who? What? ... Me?


« Reply #5 - Posted 2012-09-11 00:24:03 »

FYI there are between 2000 and 8000 sprites in a single frame of Revenge of the Titans during a massive battle. Each object on the screen is made up from about 3-5 different sprites, drawn on top of each other and animated pseudoindependently.

Cas Smiley

Offline Oskuro

JGO Coder


Medals: 16


Coding in Style


« Reply #6 - Posted 2012-09-11 04:13:40 »

Niiice. I'll just do what comes more comfortable then. Thanks

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!
 
Browse for soundtracks for your game!

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 (139 views)
2013-05-17 21:29:12

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

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

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

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

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

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

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

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

UnluckyDevil (239 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.089 seconds with 21 queries.