Page 1 of 1

Sprite zorder

Posted: Mon Oct 05, 2015 5:56 am
by orlanrod
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.

Re: Sprite zorder

Posted: Mon Oct 05, 2015 8:26 am
by Stef
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

Posted: Mon Oct 05, 2015 3:17 pm
by orlanrod
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.
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.

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;
}

}