Basic spriting done

Published May 18, 2007
Advertisement

A pyramid of stars!

I decided it wasn't worth getting bogged down on throwing in too many features into the spriting code yet - I won't know what I'll need until I need to make a game with it. So I just put in the basic minimum to get working functionality. The game code can set a sprite's:
  • type (what it looks like)
  • position (absolute or relative)
  • rotation (absolute or relative)
  • scale (absolute or relative again), and
  • depth (once again, absolute or relative)


The depth is the special one of those cases, as it's the factor that determines what order the sprites need to be rendered in. For now I've got the graphics code resorting the sprite list every time the depth is changed for a sprite. When I get to speeding up the spriting code I'll tinker with some variants on insertion sort routines to see if this can be improved, but it works for now.

The sample image above shows 121 star disc sprites arranged in a grid. Without the depth code they'll be ordered in accordance with when they were created. With the depth code but left the starting depth of zero these disks are in a slightly random order (which suggests the std::list::sort routine isn't standard insertion sort - what are they using instead?). As shown in the image, each disk is given a depth equal to the Manhattan distance (that is, the sum of the vertical and horizontal distance) from the centre of the screen, which puts the centre disc on top. I've made smaller depths be closer to the screen than larger ones, the idea being the deeper something is the more buried it is.

I've decided to cancel the collision detection and physics part of the engine, since I feel that's far better to develop with an application in mind rather than just as a general engine. For now I'll get the absolute bare minimum features required to build a simple game up and running. This means I need basic animation services and text before moving from graphics to timers, input and audio.
0 likes 2 comments

Comments

Ravuya
Ooh, depth is slick. Is there a maximum number of layers?
May 19, 2007 12:56 AM
Trapper Zoid
Quote:Original post by Ravuya
Ooh, depth is slick. Is there a maximum number of layers?

Only as much as a float can represent. I suppose in essence that means there's only one layer [smile].

Depth is implemented merely by sorting all the sprites by value; pretty simple method but it works for the prototype. It also shouldn't be too bad a method for a more final implementation as in most games sprites don't change depth that often (or if they do, there's only a handful that do so). I may end up implementing some kind of layering system later when I sketch out some methods for speeding things up as it may help with batching textures into sprite sheets, but I'd like it to remain layerless if possible.
May 19, 2007 02:43 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement