Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Load a sprite once and display it multiple times in window?

I wanted to create an object that can be spawned dynamically, so I do not know how many of these will be needed at the beginning. So TLN_LoadSpriteset loads my sprite (e.g. a fireball) and I assign it via TLN_SetSpriteSet. So to set the sprite position in the viewport I use TLN_SetSpritePosition. However, this function expects the id of the sprite which are set in TLN_Init via the numsprites parameter. If I understand this correctly and using a fireball as sprite, I am limited with spawning new fireballs by the numsprites parameter. So if I set it to 1 at the beginning I would only be able to create one fireball. 

I did not took a lock at the implementation right now. So for me it looks like for every used sprite the sprite needs to be actually loaded in order to be shown in the window. Is this correct?

I was expecting that I load a sprite once and then use it to display as many objects in the window as I would like to. Is this possible?


In Tilengine, like in any 2D graphics chipset, you can't create sprites dynamically, but are limited to a predefined amount. You choose this initial amount. For example the Sega Genesis had 80 sprites, the SNES had 128, and the NeoGeo 380. You configure, enable and disable sprites based on their fixed index. But you don't create or destroy sprites.

Let's assume you have a spriteset in the pair of files "bullets.tsx" and "bullets.png", with many bullets, and one of them is called "fireball".
/* Load the spriteset once and find the desired graphic: */
Spriteset bullets = TLN_LoadSpriteset("bullets");
int fireball = TLN_FindSpritesetSprite(bullets, "fireball");

/* set sprite 5 and 6 with fireball. Do for as many sprites as you wish */
TLN_SetSpriteSet(5, bullets);
TLN_SetSpritePicture(5, fireball);
TLN_SetSpriteSet(6, bullets);
TLN_SetSpritePicture(6, fireball);

Hope this makes some sense now, let me know!

thanks. Ah ok, yes it's a bit clearer how this works now. Thanks.

But I still do not understand why this limitation is intentional in 2D graphics chipsets. Whats the argument why it is done this way?
This limitation is because of any limitation in hardware. In 2D chipsets, each sprite and background layer is implemented in a chunk of silicon, and mapped to fixed memory positions. So their number is always fixed, just as the number of shaders (or CUDA cores) in any modern GPU is always fixed because they're chunks of silicon too. They can be enabled/disabled/adjusted or allocated to do a given task, but they cannot be created or destroyed.

However, modern graphic APIs hide away the architecture of the cores and expose an abstract model, whereas in classic 2D systems the game programmer must explicitly allocate and manage the hardware sprites because there wasn't any middleware or abstraction layer.

In Tilengine this is a design choice, to have a fixed number of reassignable sprites. This is how 2D chipsets work, and having deterministic identifiers is better for the raster effects, where one can reconfigure the resources (sprites or layers) in the middle of a frame, between scanlines.
Ah ok, that's interesting, didn't know that. Thanks for explaining this.

Forum Jump:

Users browsing this thread: 1 Guest(s)