Page 1 of 1

SPR_setDepth not working?

Posted: Wed Mar 13, 2019 8:56 pm
by cloudstrifer
Hi.

I have noticed a strange behavior with SPR_setDepth method, it not working with SPR_setDepth(arrObjects[carryIndex_p1], SPR_MIN_DEPTH);.
Why the barrel is not over Goofy?

Video on Youtube
https://youtu.be/G1yp5I6KRA0

Thank you!

Code: Select all

Sprite *arrObjects[20];
Sprite *arrBridge[2];
Sprite *arrRope[4];

SPR_setDepth(arrBridge[0], SPR_MAX_DEPTH);
SPR_setDepth(arrBridge[1], SPR_MAX_DEPTH);
SPR_setDepth(arrRope[0], SPR_MIN_DEPTH);
SPR_setDepth(arrRope[1], SPR_MIN_DEPTH);
SPR_setDepth(arrRope[2], SPR_MIN_DEPTH);
SPR_setDepth(arrRope[3], SPR_MIN_DEPTH);
SPR_setDepth(gun_p1, SPR_MIN_DEPTH);
SPR_setDepth(arrPlayers[0], SPR_MIN_DEPTH);

if (carryIndex_p1 != EMPTY)
{
	carryObject(0, carryIndex_p1);			
	SPR_setDepth(arrObjects[carryIndex_p1], SPR_MIN_DEPTH);	
}

Re: SPR_setDepth not working?

Posted: Thu Mar 14, 2019 1:54 pm
by Stef
What is the depth of Goofy ? If Goofy is also set at MIN_DEPTH then order between the two is undetermined.

Your game looks really nice by the way :)

Re: SPR_setDepth not working?

Posted: Fri Mar 15, 2019 2:11 pm
by cloudstrifer
Thank you Stef, I am your fan.

SGDK is so good!

That solved the problem, but I don't know if it is a good pratice.

Code: Select all

		...
		SPR_setDepth(arrBridge[0], SPR_MAX_DEPTH);
		SPR_setDepth(arrBridge[1], SPR_MAX_DEPTH);
		SPR_setDepth(arrRope[0], SPR_MIN_DEPTH + 50);
		SPR_setDepth(arrRope[1], SPR_MIN_DEPTH + 49);
		SPR_setDepth(arrRope[2], SPR_MIN_DEPTH + 48);
		SPR_setDepth(arrRope[3], SPR_MIN_DEPTH + 47);
		SPR_setDepth(gun_p1, SPR_MIN_DEPTH + 46);
		SPR_setDepth(arrPlayers[0], SPR_MIN_DEPTH + 45);		

		if (carryIndex_p1 != EMPTY)
		{			
			SPR_setDepth(arrObjects[carryIndex_p1], SPR_MIN_DEPTH + 44);
			carryObject(0, carryIndex_p1);			
		}
		...

Re: SPR_setDepth not working?

Posted: Fri Mar 15, 2019 5:39 pm
by Stef
You can actually put 2 objects on same depth but so the order of display between the 2 is undefined, this is expected.
Here you just need to put player sprite between barrel and bridge, you don't have other way of doing that. You have to define how many different depth levels you need then adjust depth of your objects according to that :)