How does DrawOrder work?

Post Reply
User avatar
baardbi
Posts: 78
Joined: Sun Jul 07, 2019 2:28 pm
Location: Norge

How does DrawOrder work?

Post by baardbi » Sat Feb 08, 2020 1:18 pm

I am having an issue where my player walks behind the NPC character. I never had this happen to me before. The player has always been in front. Also the text box for the NPC is behind both the player and the NPC, making it hard to read. How can I adjust these things?
User avatar
dale_coop
Posts: 4715
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: How does DrawOrder work?

Post by dale_coop » Sat Feb 08, 2020 9:24 pm

The textbox will always be behind the objects. Because it's made from Bg tiles.
Try to design your screen for always having the npc and the player on the bottom / under the textbox area.
Another solution would be to hide all the objects when a textbox is displayed: viewtopic.php?p=13559#p13559

For the DrawOrder... the function checks the top position of each object, if the top is lower, it will be rendered in front. if upper, it will be displayed behind.
If you are making a Platformer you could use the cycling to have the Player always in front of the other objects: viewtopic.php?f=40&t=2455

If you are making a Adventure Top Down game, a better code would be to check the bottom of the objects instead of the top: if the bottom is lower, the object should be in front of the others..
Here's the "UpdateDrawOrder" subroutine for that (to replace the one in the HandleUpdateObjects.asm script)

Code: Select all

UpdateDrawOrder:
	LDX #$1
OrderLoop:
	LDY drawOrder,x
	LDA Object_y_hi,y
	CLC
	ADC Object_bottom,y
	STA temp
	LDY drawOrder-1,x
	LDA Object_y_hi,y
	CLC
	ADC Object_bottom,y
	CMP temp
	BCS doneWithSwapItem
	LDA drawOrder,x
	STA drawOrder-1,x
	TYA
	STA drawOrder,x
doneWithSwapItem:
	INX
	CPX #TOTAL_MAX_OBJECTS
	BNE OrderLoop
	RTS
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
User avatar
baardbi
Posts: 78
Joined: Sun Jul 07, 2019 2:28 pm
Location: Norge

Re: How does DrawOrder work?

Post by baardbi » Sat Feb 08, 2020 9:50 pm

What a great answer! Thank you very much :)
User avatar
red moon
Posts: 416
Joined: Mon Aug 12, 2019 12:19 am

Re: How does DrawOrder work?

Post by red moon » Tue Feb 11, 2020 3:10 am

This is really helpful, to have it explained in that way. I wondered that myself!
Post Reply