[4.1.5] Sprite Cycling

vanderblade
Posts: 138
Joined: Mon Jan 07, 2019 5:20 am

Re: [4.1.5] Sprite Cycling

Post by vanderblade » Tue Jul 07, 2020 1:18 pm

Is there a way to activate the sprite flicker ONLY when four or more sprites appear on the same horizontal row? For me, this change causes the enemy sprites to constantly flicker regardless of how many or position.
User avatar
AllDarnDavey
Posts: 227
Joined: Sat Jan 12, 2019 6:16 am
Location: Seattle

Re: [4.1.5] Sprite Cycling

Post by AllDarnDavey » Tue Jul 07, 2020 9:30 pm

vanderblade wrote:
Tue Jul 07, 2020 1:18 pm
Is there a way to activate the sprite flicker ONLY when four or more sprites appear on the same horizontal row? For me, this change causes the enemy sprites to constantly flicker regardless of how many or position.
Huh... that's strange. The code doesn't actually turn drawing of sprites on or off at all. It just cycles the sprite order each frame so that IF you go over the 8 sprite per line limit then the sprites the hardware doesn't draw change every frame. If you don't have more than 8 frames in a horizontal line, you shouldn't see any change.

The only possible things I can think of that could cause your issue (provided the code is copied correctly) are: two overlapping sprites will swap which draws in front even if you are not over the limit (could cause issues with sprite layering, not really flicker, but has a similar look). Another possibility is if you're butting up against the hard limit of 64 max sprites. Besides the 8 sprites per line limit, the NES also has a total limit of 64 sprites, if you're game has so many sprites that you're hitting that limit, the cycling would still switch out which objects are turned off per frame, but the flickering would probably appear more random. Also note it's sprites, not objects. An enemy that is 2x2 eight-by-eight blocks is 4 sprites even know it is only 1 object.

Also, this was written for NesMaker 4.1.5, I have not tested or tried to port this to NesMaker 4.5 at all yet, so if you're trying to use this with the newest version of NesMaker I have no idea what it will do.
vanderblade
Posts: 138
Joined: Mon Jan 07, 2019 5:20 am

Re: [4.1.5] Sprite Cycling

Post by vanderblade » Tue Jul 07, 2020 9:34 pm

I've had better luck with Dale's version, but it has its own bugs in my game (some enemy's only appear after I fire my projectile). It doesn't matter much, since we're all moving on to 4.5. Just thought I'd share in case anybody else had a similar issue.

Code: Select all

UpdateDrawOrder:
	;JMP DoNormalDrawOrder	;; to use the normal draw order
	JMP DoFlickeringDrawOrder	;; to use the one giving priority to the player
	
DoFlickeringDrawOrder:
	;Now with sprite cycling
	LDX #$1
OrderLoopFlickering:

	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.
	LDY drawOrder-1,x

	LDA Object_flags,y
	AND #%00000110		;; if it's a player or player weapon
	BNE doneWithSwapItemFlickering	;; we skip it

	;LDA Object_y_hi,y
	CMP temp
	BCS doneWithSwapItemFlickering
	LDA drawOrder,x
	STA drawOrder-1,x
	TYA
	STA drawOrder,x
doneWithSwapItemFlickering:
	INX
	CPX #TOTAL_MAX_OBJECTS
	BNE OrderLoopFlickering
	RTS

DoNormalDrawOrder:
	LDX #$1
OrderLoop:

	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.
	LDY drawOrder-1,x
	LDA Object_y_hi,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
User avatar
AllDarnDavey
Posts: 227
Joined: Sat Jan 12, 2019 6:16 am
Location: Seattle

Re: [4.1.5] Sprite Cycling

Post by AllDarnDavey » Tue Jul 07, 2020 10:01 pm

I wasn't aware Dale had a different version of sprite cycling. Did he post it to facebook or discord rather then the forums (I'm rarely on discord, and I'm almost never on facebook)?

Dale definitively has more experience with 6502 assembly, and NesMaker in general then I do, so I'd be interested if he had a more elegant solution then the one I cobbled together. I'm also curious how some classic games handle it. I know MegaMan for example uses sprite layering for MegaMan's face, so they must've done a version that doesn't break sprite layering.
Post Reply