Changing sprite draw order [4.1.5]

Has anybody messed with sprite draw order yet?

I want to make the player draw on top of all other sprites. I don't mind messing with system scripts, just haven't been able to find where draw order is yet.

Its a minor gripe, but in the platformer module, whenever I walk up to an NPC the player goes behind them, which looks really ugly because I cheated and used the background color in my NPC so if the player goes behind them parts of them are transparent. If the player drew on top of them then they would look fine.
 
I solved my question :)

Here is the edited code if anybody else wants it:
(works in 4.1+ platformer modules)

in HandleUpdateObjects.asm, replace your UpdateDrawOrder subroutine with this:
Code:
UpdateDrawOrder:
	
    ;; Start the loop
	LDX #$1
OrderLoop:

    ;; Get the draw priority of the current object, and store it in temp
	LDY drawOrder,x
	LDA Object_y_hi,y
	STA temp
	;;;; what would drawOrder-1 be?  if it is 0, would would have to become 0f.
    
    ;; Get the draw priority of the previous object
	LDY drawOrder-1,x
    CPY player1_object ;; if previous is player object, don't swap them.
    BEQ doneWithSwapItem
	LDA Object_y_hi,y
	CMP temp    ;; compare their height
	BCS doneWithSwapItem ;; If previous height > current height, then previous behind current is correct. 
    
swapDrawOrder:
	;; Otherwise swap the order
    LDA drawOrder,x
	STA drawOrder-1,x
	TYA
	STA drawOrder,x
    
    
doneWithSwapItem:
	INX
	CPX #TOTAL_MAX_OBJECTS
	BNE OrderLoop
	RTS
 

AllDarnDavey

Active member
Hmm... interesting.

I wonder if you could tweak this for sprite flickering for more than 8 sprites on a scanline.
 
Top Bottom