Tilengine - The 2D retro graphics engine forum

Full Version: Sprite priority?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there some way to make a sprite appear in front of one layer but behind another, so that the layer obscures the sprite?
Yes, layer vs. sprite priority is available but it's a bit undeveloped. Priority is implemented per individual tile and not per full layer: in any given tilemap, you can have some (or all tiles) show in front of sprites. This is accomplished by setting the FLAG_PRIORITY flag in the Tile structure for the desired tiles(s), and the functions TLN_GetTileMapTile() and TLN_SetTilemapTile(). If you want to enable priority on the full tilemap, you could use this helper function:


Code:
void SetTilemapPriority (TLN_Tilemap tilemap)
{
    const int num_rows = TLN_GetTilemapRows (tilemap);
    const int num_cols = TLN_GetTilemapCols (tilemap);
    int row, col;
    
    for (row=0; row<num_rows; row++)
    {
        for (col=0; col<num_cols; col++)
        {
            Tile tile;
            TLN_GetTilemapTile (tilemap, row, col, &tile);
            tile.flags |= FLAG_PRIORITY;
            TLN_SetTilemapTile (tilemap, row, col, &tile);
        }
    }
}

I'll add a property for Tiled editor loader where you will be able to set tile priority right there.
Ah, so I can't have some sprites appear in front of a layer and some behind?  Ideally I'd be able to just give each sprite a number that assigns it to a layer and the screen would be drawn back to front.
Classic systems don't work this way. Instead, each sprite and each individual tile can have a “priority bit” set. The final layout is determined based on combinations of these priority bits, in decreasing order of priority:

  1. Sprites with priority bit set
  2. Tiles with priority bit set
  3. Sprites without priority bit
  4. Tiles without tile priority
  5. Background color
At this point (release 1.15) tilengine only implements tile priority, not sprite priority, but I plan adding it.
Ah I understand. This should work for my case then. Thanks!
Wow, I didn't realise classic systems worked that way Smile

I think simplifications like this can be very good. Sure you have to make careful decisions about how to lay out your scene, but sometimes you realise you didn't need as much stuff as you thought you did, and the code becomes simpler because there's less possibilities to cater for! That's what I appreciated about developing in Pico-8.
Having to work in constrained environments makes creativity flourish. The 8-bit and especially the 16-bit era gave birth to many impressive exercises of wizardry. I admire all those talented guys that devised creative ways to achieve seemingly impossible effects on such hardware.

I strongly recommend you guys reading this forum thread, talks about 16-bit games that pushed the limits, and gives explanations about how they were achieved. Some effects across the thread are unbelievable even today.
http://www.neogaf.com/forum/showthread.php?t=1247148

Tilengine was created to provide a similar environment, although without many of the limitations that real hardware imposed. I admire the creativity behind an impressive effect on a limited environment, not an impressive effect on an even more impressive hardware that's the tendency nowadays.

I'll have to check the Pico-8! Smile
You should Smile It's like he went back in time and just brought forward the best bits of retro stuff and all the lessons learned, to make the most appealing mini-computer hardware (emulated) ever. Especially the chosen colours for the fixed 16 colour palette, and the chosen instruments for the chiptune generator.

Thanks for the link to the thread! Yeah there are games like Red Zone, and Batman (both megadrive games) who's design principal appeared to be "We can't add anything to this game unless it's pushing the hardware in some way!"

Yeah it's good to have some of the aesthetic restrictions but not the resource restrictions, so you can make cute retro games but in a huge world.
I agree, Red Zone and Batman & Robin for megadrive have some effects that I can't figure how to replicate with tilengine...

When I designed tilengine I was pursuing the raster effects thing, but I didn't want to replicate other limitations artificially. There are many areas where tilengine is much more friendly to work with -I should make a list-, but it inherits features that were used for creative effects, as the per-column vertical offset or tile-based priority.

I'm working in the lacking documentation, when I finish it i have to give a look to the pico-8. This system, as a standard, is good for creativity: everybody works with the same resolution, colors, sounds and processing power. You have a finite set of choices that forces you to be creative and efficient. This was one of the big great points of 8-bit home computers: fixed restrictions for everybody. The other was accessibility to programming: power on, take the manual and start making experiments.

In today's systems it's easy to get lost: an endless sea of possibilities, no fixed limitations, stacks of abstraction layers, countless languages, engines and development environments... too much freedom is not always good for creativity and getting focused.
So true! Like right now in the other thread I just made, hahha...

And you're bang on with Pico-8 - you'll see it even has a website where you can play the games in your web browser directly, easily the best way to distribute your games!