Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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 2388 times)
0 Members and 1 Guest are viewing this topic.
Offline Oskuro

JGO Knight


Medals: 39
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: 27
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 Kernel


Medals: 386
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: 39
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 Kernel


Medals: 386
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: 39
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.

 

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

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (43 views)
2014-09-23 14:38:19

radar3301 (25 views)
2014-09-21 23:33:17

BurntPizza (62 views)
2014-09-21 02:42:18

BurntPizza (32 views)
2014-09-21 01:30:30

moogie (37 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!