When should I use sprites

Sprites have been added to the engines interface, to implement fast 2d graphics. If you are planning to write a 2d game, that displays hundreds of little objects that animate and move around, than you should use sprites.
If you need a game menu or a hud to display the hitpoints or some inventory, you should use function "renderStretchedPic()".




Layers

Using "renderStretchedPic()" you draw one picture over the other, so the first drawn picture is covered by the second and so on.
Using sprites, the engine is responsible for the rendering. You force the engine to render all sprites once, by calling function: "sce::renderRegisteredSprites()". To define a rendering order, you use the layers. Every sprite lives in a layer, where layer 0 is the most far away one, followed by the layers 1,2,3,...,9.




How to use

To use sprites correctly and make the rendering as fast as possible, you have to follow these rules:

  1. try to group animation sequences of a single object in one big texture
  2. try to group objects that share the same texture in the same layer
Keeping this in mind the engine will take care of the rendering. If you have no idea what i mean with "grouping sequences of animation in a single texture", look into "tutorial 5(sprites)". The screenshot shows a texture on the left, that holds some possible animations for a space ship.

"Tutorial 5(sprites)" loads a sprite object and gives the user a chance to change the animation state. Have a look into the source code for this tutorial, to see how to load, access and render sprites.





SourceForge.net Logo