How to change sprite palettes [Solved!]

kainminter

New member
My game's design hinges on being able to change the palette of the player in game, so I really hope it is possible but I'm not having any luck.

I have not been able to get it to work with the LoadSpritePalette macro, as it seems to crash the game to use this.

I learned that the colors for sprite palette 1 are stored in $3F10 - $3F13 so I've tried manually setting the colors in memory like this:

Code:
	LDA #$16
	STA $3F11
	LDA #$27
	STA $3F12
	LDA #$38
	STA $3F13

But it does not work. The screen flashes momentarily only, no change of color.I fear I may either be doing it wrong or I may be trying to do something that is not possible anyway.
Any help overcoming this hurdle would be greatly appreciated m(_ _)m
 

drexegar

Member
kainminter said:
My game's design hinges on being able to change the palette of the player in game, so I really hope it is possible but I'm not having any luck.

I have not been able to get it to work with the LoadSpritePalette macro, as it seems to crash the game to use this.

I learned that the colors for sprite palette 1 are stored in $3F10 - $3F13 so I've tried manually setting the colors in memory like this:

Code:
	LDA #$16
	STA $3F11
	LDA #$27
	STA $3F12
	LDA #$38
	STA $3F13

But it does not work. The screen flashes momentarily only, no change of color.I fear I may either be doing it wrong or I may be trying to do something that is not possible anyway.
Any help overcoming this hurdle would be greatly appreciated m(_ _)m

It works differently in nesmaker here is the code:

Color Change

;; suppose you wanted to change the 3rd sprite palette, and the 2nd background palette

;; You load up the color you want into the accumulator, then store it into spritePalFade/bckPal PLUS the index of the palette color you want to change (0-15)
;; +0-3 = 1st palette
;; +4-7 = 2nd palette
;; +8-11 = 3rd palette
;; +12-15 = 4th palette

LDA #$0F ; black
STA spritePalFade+8 ; 3rd sprite palette, 1st color
LDA #$00 ; dark grey
STA spritePalFade+9 ; 3rd sprite palette, 2nd color
LDA #$10 ; light grey
STA spritePalFade+10 ; 3rd sprite palette, 3rd color
LDA #$20 ; white
STA spritePalFade+11 ; 3rd sprite palette, 4th color

;; Now we do the same for the background palette

LDA #$0F ; black
STA bckPal+4 ; 2nd background palette, 1st color
LDA #$00 ; dark grey
STA bckPal+5 ; 2nd background palette, 2nd color
LDA #$10 ; light grey
STA bckPal+6 ; 2nd background palette, 3rd color
LDA #$20 ; white
STA bckPal+7 ; 2nd background palette, 4th color

;; IMPORTANT!!!
;; Once you've done all the palette changes you want, you're going to load a non-zero number into the variable updatePalettes
;; This will tell the palette update script that runs during vblank to make the appropriate PPU writes
;; If you forget to load a non-zero number into updatePalettes, your palette changes will fail to update, and you will be sad :(

LDA #$01
STA updatePalettes
RTS
 
Top Bottom