SciNEStist
Well-known member
One of the things that makes a game seem to have that extra bit of polish is when you load up a level or map and it fades in to existence from blackness.
This script requires you to first implement this fix to correct the problem with the transparent background colour : FIND IT HERE
This scripts features:
STEP 1: under Palettes > All Palettes, scroll to the bottom and turn Palette #63 into all black
STEP 2: in the project settings window under user variables, add "fade" with an initial value of 0
STEP 3: also in project settings, under project labels, click "Screen Flags" and change "Screen Flag 7" to "Fade in from black"
STEP 4: in your BASE_4_5\Game\Subroutines folder, open up doLoadScreen.asm and scroll to about line 50. we are looking for this:
replace it with this:
This will make it so any screens that have "Fade in from black" checked will start as solid black instead of the regular palette.
STEP 5:
NOTE: if your module doesn't use a camera script, then save this code anywhere that gets ran every frame and is saved to the main bank (1F)
In NESMaker, click Scripts>Defined Scripts>Subroutines>Handle Camera and at the top of the doUpdateCamera.asm, add this code:
DONE!
Now, if you want a screen to fade in from black whenever it is loaded, simply check the flag in screen settings
This script requires you to first implement this fix to correct the problem with the transparent background colour : FIND IT HERE
This scripts features:
- only about 75 lines of code
- only 1 new user variable
- easy to add to existing games
- fades all background colours including the transparent colour
- fully noted script, great for learning
STEP 1: under Palettes > All Palettes, scroll to the bottom and turn Palette #63 into all black
STEP 2: in the project settings window under user variables, add "fade" with an initial value of 0
STEP 3: also in project settings, under project labels, click "Screen Flags" and change "Screen Flag 7" to "Fade in from black"
STEP 4: in your BASE_4_5\Game\Subroutines folder, open up doLoadScreen.asm and scroll to about line 50. we are looking for this:
Code:
LoadBackgroundPalettes newPal
replace it with this:
Code:
LDA ScreenFlags00
AND #%00000001
BNE +
LoadBackgroundPalettes newPal
JMP +donebgpal
+
LoadBackgroundPalettes #63
LDA #$01
STA fade
+donebgpal
This will make it so any screens that have "Fade in from black" checked will start as solid black instead of the regular palette.
STEP 5:
NOTE: if your module doesn't use a camera script, then save this code anywhere that gets ran every frame and is saved to the main bank (1F)
In NESMaker, click Scripts>Defined Scripts>Subroutines>Handle Camera and at the top of the doUpdateCamera.asm, add this code:
Code:
;;FADE IN STUFF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LDA fade
BNE +
JMP +nofadein ; if fade = 0, then we are not doing anything
+
CMP #$10 ; STEP 4, LOAD REGULAR PAL at frame 16
BNE +
LoadBackgroundPalettes newPal ; load screen palette
LDA #$00
STA fade ; set fade to 0
JMP +nofadein ; jump to end
+
TXA ;these 4 lines are to preserve our x and y registers (although we dont currently do anything to x register)
PHA
TYA
PHA
SwitchBank #$16 ; go to the bank that has the data
LDY newPal ; grab the screens pallette setting
LDA GameBckPalLo,y
STA temp16 ; saves what we need to temp16
LDA GameBckPalHi,y
STA temp16+1
LDY #$00 ; sets y to zero so we can start our loop right
LDA fade
CMP #$04 ; 4 frames in, we do step 1
BNE +
LDA #$2F ; in this step, any color over value 2F will get reduced and updated
STA tempx
JMP fadeinloop ; STEP 1, mostly dark
+
CMP #$08 ; 8 frames in, we do step 2
BNE +
LDA #$1F ; in this step, any color over value 1F will get reduced and updated
STA tempx
JMP fadeinloop ; STEP 2, bit lighter
+
CMP #$0C ; 12 frames in, we do step 3
BNE +
LDA #$0F; in this step, any color over falue 0F will get reduced and updated
STA tempx
JMP fadeinloop ; STEP 3, lighter still
+
JMP NoFadechange ; if it doesnt land on any of those frames, we skip ahead with no change
fadeinloop: ;this loop goes through each palette and subtracts tempx from it. each step is less of a subtraction. lower numbers are brighter
LDA (temp16),y ; load up the true palette
CMP tempx
BCC +
CLC
SBC tempx ; subtract from the palette
STA bckPal,y ; save our new darkened palette
+
INY
CPY #$10
BNE fadeinloop ;if we havent done all 16, we go back and do it again
;if we are done with the loop, we proceed
LDA updateScreenData
ORA #%00000001 ;; palette
STA updateScreenData ; we tell the game it needs to update the screen
NoFadechange:
ReturnBank ; get back to the normal bank
PLA ; These four lines restore the x and y registers
TAY
PLA
TAX
INC fade ; we increase the variable count to act as a ticker
+nofadein
;;DONE FADE IN STUFF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DONE!
Now, if you want a screen to fade in from black whenever it is loaded, simply check the flag in screen settings
Last edited: