Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (593)
Games in Android Showcase (168)
games submitted by our members
Games in WIP (646)
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 2642 times)
0 Members and 1 Guest are viewing this topic.
Offline Oskuro

JGO Knight

Medals: 44
Exp: 6 years

Coding in Style

« Posted 2012-09-10 16: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

Offline sproingie

JGO Kernel

Medals: 202

« Reply #1 - Posted 2012-09-10 17: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 Knight

Medals: 33
Exp: 18 years

Computers can do that?

« Reply #2 - Posted 2012-09-10 18: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!
Legends of Yore - The Casual Retro Roguelike
Offline princec

« JGO Spiffy Duke »

Medals: 545
Projects: 3
Exp: 16 years

Eh? Who? What? ... Me?

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

Assemble on the fly.

Cas Smiley

Offline Oskuro

JGO Knight

Medals: 44
Exp: 6 years

Coding in Style

« Reply #4 - Posted 2012-09-10 22: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

« JGO Spiffy Duke »

Medals: 545
Projects: 3
Exp: 16 years

Eh? Who? What? ... Me?

« Reply #5 - Posted 2012-09-10 22: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 Knight

Medals: 44
Exp: 6 years

Coding in Style

« Reply #6 - Posted 2012-09-11 02: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.

Riven (16 views)
2015-07-03 11:22:16

deepthought (44 views)
2015-06-30 15:39:44

deepthought (48 views)
2015-06-30 15:39:09

deepthought (60 views)
2015-06-30 15:36:52

Za\'Anzabar (28 views)
2015-06-29 05:44:54

TritonDreyja (44 views)
2015-06-24 17:10:40

CopyableCougar4 (43 views)
2015-06-23 00:34:45

BurntPizza (46 views)
2015-06-21 20:36:46

cookiecompiler (88 views)
2015-06-11 15:42:53

cookiecompiler (51 views)
2015-06-11 15:41:14
How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
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!