(4.5.6) Using userScreenBytes to Draw a Sprite on Screen

TolerantX

Active member
First: do this: http://nesmakers.com/viewtopic.php?f=35&t=5842

Okay Here we go! :)
(I use userScreenByte2 in my scripts)
create a blank asm we will name doSpritePredraw (or what you will use for yours)
open your project settings and look for Script Settings "sprite pre-draw"
now make it point to where your blank doSpritePredraw is.
everything should be fine...
okay now note that in my script it draws from the bottom left of game objects.bmp
I have a rudimentary video I will post at the bottom of this post to show the process and some things you can change...
here is a script:

Code:
;;; sprite pre draw ;;;

	LDA userScreenByte2					;; Loads variable for drawing sprite on/off per screen ;;
	CMP #$01				;; for some reason screen flags wont work so we are doing it this way ;;		
	BEQ +DrawThisToHud		;; if the screen has 1 as the screen byte2 then it draws the knight ;;
		JMP +skipDrawThisToHud		;; if not, it doesnt draw ;;
+DrawThisToHud:
	DrawSprite #$4F, #$CF, #$70, #%00000010   ;; KnightTopL ;;
	DrawSprite #$57, #$CF, #$70, #%01000010   ;; KnightTopR ;;
	DrawSprite #$4F, #$D7, #$71, #%00000010   ;; KnightBotL ;;
	DrawSprite #$57, #$D7, #$71, #%01000010   ;; KnightBotR ;;

+skipDrawThisToHud:

endScript:
	RTS

Keep in mind these are my settings... okay now look at the script. you can have it check for 2 or 3 or 4 etc if you like...
This is what I mean.. this is for 0 none, 1 draws this, and 2 draws that:

Code:
;;; sprite pre draw ;;;

	LDA userScreenByte2					;; Loads variable for drawing sprite on/off per screen ;;
	CMP #$01				;; for some reason screen flags wont work so we are doing it this way ;;		
	BEQ +DrawThisToHud		;; if the screen has 1 as the screen byte2 then it draws the knight ;;
		JMP +skipDrawThisToHud		;; if not, it doesnt draw ;;
+DrawThisToHud:
	DrawSprite #$4F, #$CF, #$70, #%00000010   ;; KnightTopL ;;
	DrawSprite #$57, #$CF, #$70, #%01000010   ;; KnightTopR ;;
	DrawSprite #$4F, #$D7, #$71, #%00000010   ;; KnightBotL ;;
	DrawSprite #$57, #$D7, #$71, #%01000010   ;; KnightBotR ;;

+skipDrawThisToHud:

	CMP #$02									
	BEQ +DrawThisToHud
		JMP +skipDrawThisToHud		;; if not, it doesnt draw ;;
+DrawThisToHud:
	DrawSprite #$4F, #$D7, #$73, #%00000001   ;; This is the flip LEFT RIGHT ;;

+skipDrawThisToHud:

	;CMP #$03									
	;BEQ +DrawThisToHud
		;JMP +skipDrawThisToHud	
;++DrawThisToHud:

;+skipDrawThisToHud:
endScript:
	RTS

Notice the commented out script? If you did some of Joe's tutorials you may remember the one about the pickup script explaining that. this uses a similar principle. You can skip this then go to that, skip that go to that until the end if need be. I leave 0 for the end if you use it, otherwise 0 will ultimately be off automatically (which I recommend just doing so it doesnt draw on EVERY screen, unless you want to)

as promised.. my failed attempt with the beta version of my script to get it to work and explain things. keep in mind that script is not as well written as this one.

https://youtu.be/EAAlCoYwCDM

This script is more lean for your game to add your draw sprites as you desire:

Code:
;;; sprite pre draw ;;;

	LDA userScreenByte2					;; Loads variable for drawing sprite on/off per screen ;;
	CMP #$01				;; for some reason screen flags wont work so we are doing it this way ;;		
	BEQ +DrawThisToHud		;; if the screen has 1 as the screen byte2 then it draws the knight ;;
		JMP +skipDrawThisToHud		;; if not, it doesnt draw ;;
+DrawThisToHud:
	DrawSprite #$4F, #$CF, #$70, #%00000010   ;; KnightTopL ;;
	DrawSprite #$57, #$CF, #$70, #%01000010   ;; KnightTopR ;;
	DrawSprite #$4F, #$D7, #$71, #%00000010   ;; KnightBotL ;;
	DrawSprite #$57, #$D7, #$71, #%01000010   ;; KnightBotR ;;

+skipDrawThisToHud:

	;CMP #$02									;
	;BEQ +DrawThisToHud
		;JMP +skipDrawThisToHud		;; if not, it doesnt draw ;;
;+DrawThisToHud:

;+skipDrawThisToHud:

	;CMP #$03									
	;BEQ +DrawThisToHud
		;JMP +skipDrawThisToHud	
;++DrawThisToHud:

;+skipDrawThisToHud:
endScript:
	RTS
 
Top Bottom