Fade to Black [4.5.6]

chains

Member
I've found the problem.

The background code is working ok, but the sprite changing is not because of the flag to update the screen in the next cycle.

If you see the code responsible to load the palettes in $2007 registry, you will see something like this:

Code:
 doPaletteUpdates:
     .include SCR_LOAD_PALETTES
     JMP skipScreenUpdates
 +
     LDA updateScreenData
     AND #%00000010
     BNE doSpritePaletteUpdates:
     JMP +
doSpritePaletteUpdates:
    .include SCR_LOAD_SPRITE_PALETTES

   ;;; this code above is in the SRC:
    LoadSpritePal_NMI:
    LDA sprPal,x
    STA $2007
    INX
    CPX #$10
    BNE LoadSpritePal_NMI
   
    LDA updateScreenData
    AND #%11111101
    STA updateScreenData

Note that the flag that needs to be set is the 7th and in this code we are setting the 8th:

Code:
        LDA #$01
        STA updateScreenData

The final working version is:

Code:
    LDX #$00
    doFadeCurrentSpritePal:
        LDA sprPal,x ;; loads joes pallete for background (0-3) (4-7) (8-11) (12-15) 4,8,and 12 is not needed since its the same color as 0
        CMP #$10 ;; compares 10
        BCC + ;; if less than 10 skip to p1, if not continue below
        SEC ;; needs for subtraction
        SBC #$10 ;; subtract #$10
        STA sprPal,x ;; store it back into pallete
        JMP goNextSpritePal;; jump to the next pal2
        +
        LDA #$0F ;; set accumalator to 0F which is (black)
        STA sprPal,x ;; store it into pallete
    goNextSpritePal:
        INX
        CPX #4
        BEQ goNextSpritePal
        CPX #8
        BEQ goNextSpritePal
        CPX #12
        BEQ goNextSpritePal
        CPX #16
        BCC doFadeCurrentSpritePal
        LDA #%00000010
        STA updateScreenData
    RTS

Another thing is, if you run this script ONCE, it will darken the colors of the pals, ONCE, and for ALL sprites on the screen.

If you don't want this, you can control which pal index you want to darken in the second portion of the code (goNextSpritePal). It controls the pal index (0-12).

So when you add this to your object details, you can make an action to Fade the Object, repeat a couple of times until all the 4 colors in the pal are turned black (#0F), and then move to DestroyObject.

I hope that this helps someone out there. @9Panzer could you try this and tell me if you managed?

What we've learned today? Don't copy someone else's code without proper understanding.
 

chains

Member
And this is how you can do to fade your hero until his death:

1) Create a new AI Reaction called "FadeOutAndRestart"
2) In the script for this reaction, add:

Code:
    JSR doFadeOutSprites
    ;; let's now check if all colors in the first pal are black
    LDX #$00
    checkIsBlack:
        LDA sprPal,x
        CMP #$0F ; black
        BEQ checkNext
            JMP returnAndCallFadeAgain
        checkNext:
        INX
        CPX #4 ;; this is the next pal (0-3), so if it's greater than 4, we stop
        BCC checkIsBlack
    endOfFading: ;; if we reach this point, means that we are done with this world, and we need to warp to the very same screen
        WarpToScreen warpMap, currentNametable, #$02
        LDX player1_object
        LDA #$00000000
        STA Object_direction,x
        ChangeActionStep player1_object, #$00
    returnAndCallFadeAgain:
RTS

What we are doing here is:

1. Fade the first hero pal using the script in my other post
2. Verifying if all the 4 colors are black, if not, we just return. The Object Engine will call us again, darken the colors and we do another round. You can control the interval using the "Timer" attribute in Nes Maker
3. If every color in the pal is black, we warp to the very same screen. You can either include this code in one bank or write a macro. It's the same one I'm using for the "RestartScreen" macro

Finally, here's my attributes:

nesmaker_fadeout_restart.png

And here's the end result:

mage-death-fading.gif
 

chains

Member
One more thing, if you want to update both background and your hero, the `updateScreenData` must be `#%00000011` since NES Maker will check different positions of this byte depending on what needs to be updated.

Here's my final result:


mage-death-fading2.gif

I'm using `timer: 1`
 

Retrofaija

Member
btw, for some reason this background palette fading just does one step of darkening and doesnt go all the way to black... in 4.5.9
 

crazygrouptrio

Active member
btw, for some reason this background palette fading just does one step of darkening and doesnt go all the way to black... in 4.5.9
That's what it's supposed to do. It shifts all palettes down by #$10, so it needs to run multiple times to get to black. Just have the script run 3-4 times on a short timer to get the effect you want.
 

Jonny

Well-known member
In the example it's a AI reaction but you can call the subroutine (JSR) from, for example, a timer or whatever makes sense in your game.
 
Top Bottom