SPR_setDepth not working?

SGDK only sub forum

Moderator: Stef

Post Reply
cloudstrifer
Very interested
Posts: 118
Joined: Mon Feb 19, 2018 7:31 pm

SPR_setDepth not working?

Post by cloudstrifer » Wed Mar 13, 2019 8:56 pm

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

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: SPR_setDepth not working?

Post by Stef » Thu Mar 14, 2019 1:54 pm

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 :)

cloudstrifer
Very interested
Posts: 118
Joined: Mon Feb 19, 2018 7:31 pm

Re: SPR_setDepth not working?

Post by cloudstrifer » Fri Mar 15, 2019 2:11 pm

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

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: SPR_setDepth not working?

Post by Stef » Fri Mar 15, 2019 5:39 pm

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 :)

Post Reply