How to do set a sprites zorder? Say if i want it to appear behind an object, or in front, depending on Y position.
Thanks.
Sprite zorder
Moderator: Stef
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: Sprite zorder
Z ordering does not really exists on Sega Genesis, what you have internally is a linked list so sprite are drawn in order they are linked. The last draw sprite is above other sprite. In SGDK, i just consider than sprites are drawn in order they appears in the sprites array so the last sprite has the highest priority. I know that solution is definitely not convenient :-/ I need to rework out a bit the sprite engine mainly for that reason.
Re: Sprite zorder
Ah, i thought you were going to say there was no solution, but this works fine. I just change the the value in the array and it works for me. Although i am not sure if it is efficient.Stef wrote:Z ordering does not really exists on Sega Genesis, what you have internally is a linked list so sprite are drawn in order they are linked. The last draw sprite is above other sprite. In SGDK, i just consider than sprites are drawn in order they appears in the sprites array so the last sprite has the highest priority. I know that solution is definitely not convenient :-/ I need to rework out a bit the sprite engine mainly for that reason.
if (posy > cposy)
{
if (triggerIndex == 1)
{
pzorder = 0;
czorder = 1;
SPR_initSprite(&sprites[pzorder], &jason_sprite, posx, posy, TILE_ATTR(PAL1, TRUE, FALSE, FALSE));
SPR_initSprite(&sprites[czorder], &fcitizen_sprite, cposx, cposy, TILE_ATTR(PAL2, TRUE, FALSE, FALSE));
triggerIndex = 0;
}
}
else
{
if (triggerIndex == 0)
{
pzorder = 1;
czorder = 0;
SPR_initSprite(&sprites[pzorder], &jason_sprite, posx, posy, TILE_ATTR(PAL1, TRUE, FALSE, FALSE));
SPR_initSprite(&sprites[czorder], &fcitizen_sprite, cposx, cposy, TILE_ATTR(PAL2, TRUE, FALSE, FALSE));
triggerIndex = 1;
}
}