[solved] object sprite's black color not changing using UpdatePalette

Started by arj0n, Wed 15/07/2020 19:23:16

Previous topic - Next topic

arj0n

So I have a 4-colour game with 8-bit colour depth in 320x420 resolution and in the game setup the software driver is set as graphics driver.
But for some (unknow to me) reason the object sprite's black color isn't updating after updating the palette codewise.
The same black in the room's background is correctly updating though...
I hope someone can explain this tpo me, I can't figure out why it works correctly for the room bg but not for object sprite...

This is the colours setting panel:
Spoiler
[close]

Here's an object's sprite seting:
Spoiler
[close]

Here's the room background and the object with said sprite:
Spoiler
[close]

when running this to update the palette to game boy colors:
Spoiler

Code: ags

  //black
  palette[0].r = 4;
  palette[0].g = 14;
  palette[0].b = 4;
  
  //cyan:
  palette[1].r = 12;
  palette[1].g = 24;
  palette[1].b = 12;
  
  //magenta:
  palette[2].r = 34;
  palette[2].g = 42;
  palette[2].b = 4;
  
 //white
  palette[3].r = 38;
  palette[3].g = 46;
  palette[3].b = 4;

  UpdatePalette();

[close]

This is how it looks, for some reason the object's black color is not changing...
It has the same black (sprite-wise) as the background... (the black color of the gate is also not changing correctly, which is another object)
Spoiler
[close]

Gilbert

There may be some quirks when you change the "fixed" colours (usually means #0 - 16) of the palette, especially entry #0.
Instead use the entries after #16 (i.e. #17 onwards, or for better management, use #32 - 35 for these backgrounds, which would be the first 4 entries of the third row).

arj0n

Thanx for responding, will try that!
I've seen some more quirks indeed, all seem to be related to entry #0...

arj0n

Well, I tried but I'm still failing to update the black colour of the object-sprites...

1. in file>preferences, option 'remap palette of room bg into allocated background palette slots': no
2. in colours panel :

slot 0-4 are set as 'background' colourtype, using the following colours:
slot 0: 0, 0, 0
slot 1: 84, 252, 252
slot 2: 252, 84, 252
slot 3: 252, 252, 252

slot 32-35 are set as 'gamewide' colourtype, using the (same) following colours:
slot 32: 0, 0, 0
slot 33: 84, 252, 252
slot 34: 252, 84, 252
slot 35: 252, 252, 252

3. object sprite has been imported using the following options:
import options:
-import alpha channel: no
-remap palette: yes
-use room background: no
Transparant colour:
-bottom-right pixel (which is 84, 84, 252)

(the room's object sprite and background both contain the same 4 cga colors as shown in the 4 color slots of ags' colours panel, see link to both files in bottom of post)

4. running the palette update, the 4 colours of the background do change correctly, but the object sprite's black color is not changing:
Spoiler

Code: ags

//room background:
  //black
  palette[0].r = 4;
  palette[0].g = 14;
  palette[0].b = 4;
  
  //cyan:
  palette[1].r = 12;
  palette[1].g = 24;
  palette[1].b = 12;
  
  //magenta:
  palette[2].r = 34;
  palette[2].g = 42;
  palette[2].b = 4;
  
  //white
  palette[3].r = 38;
  palette[3].g = 46;
  palette[3].b = 4;
  
  //objects:
  //black:
  palette[32].r = 4;
  palette[32].g = 14;
  palette[32].b = 4;
  
  //cyan:
  palette[33].r = 12;
  palette[33].g = 24;
  palette[33].b = 12;
  
  //magenta:
  palette[34].r = 34;
  palette[34].g = 42;
  palette[34].b = 4;
  
  //white
  palette[35].r = 38;
  palette[35].g = 46;
  palette[35].b = 4;

  UpdatePalette();

[close]

Result:


Here's the original (cga-colors) background and the object sprites:
https://dam1976.home.xs4all.nl/AGS/curse/BG.png
https://dam1976.home.xs4all.nl/AGS/curse/object1.png
https://dam1976.home.xs4all.nl/AGS/curse/object2.png

Gilbert

Try setting remap palette to "no". Setting it to "yes" would probably remap the black colour of the sprites to colour entry #0.
(The advices on sprite importing in my linked tutorial above should still be relevant.)

arj0n

I'm utterly confused now, nothing seem to work.  8-0

I'm still not able to switch the black sprite color for the objects to dark green (using UpdatePalette), and importing sprites using "remap palette" set to "no" messes up some sprites...
It seems I have to give up on it, i just can't seem to get it to work correctly.

Some info
slot 0-4 are set as 'gamewide' colourtype, using the following colours:
slot 0: 0, 0, 0
slot 1: 84, 252, 252
slot 2: 252, 84, 252
slot 3: 252, 252, 252

slot 16-19 are set as 'background' colourtype, using the following colours (the same as the 4 gamewide colors):
slot 32: 0, 0, 0
slot 33: 84, 252, 252
slot 34: 252, 84, 252
slot 35: 252, 252, 252

all other slots are unused, I've set them to black (0,0,0) and to background.

when importing the sprite (the one shown in the upper righthand corner of the screenshot in my previous post) using these settings:
import options:
-import alpha channel: no
-remap palette: no
-use room background: no
Transparant colour:
-bottom-right pixel (which is 84, 84, 252)

it got its colours messed up.

importing and imported the object#1 sprite (messed up):


importing and imported the object#2 sprite (imports correctly):


colours are setup like this:


room in editor with object#1 sprite having messed up colors and object#2 showing correctly):


running the UpdatePalette, still black background instead of GB 'darkgreen' (should be 4,14,4 as in values from 0 to 63 or 15,56,15 values from 0 to 255):

Cassiebsg

I know this won't solve the original problem, but have you tried not using pure black? And using the next closest to black possible? Even if only to test that works, and that the problem is in fact pure black.
There are those who believe that life here began out there...

arj0n

I tried this the other way around, starting with the gameboy palette, sprites and bg. Switching to cga works fine but switching back to gb fails showing pure black instead of dark green. So yes, it seems black or slot#0 is the problem. I just don't understand how to tackle this. I read Gilbert's tutorial but  I still can't find the solution... It looks so simple, just four colors, but i have no clue that the true problem is...

eri0o

Is it possible to ignore slot zero and always work with the ones after? Just in case there's something different with slot 0.

Gilbert

Haven't read it all as I'm on mobile.
If slots 16-19 are set to bg colours and you import sprites with "use room bg" set to "no" then the sprites won't use these colour slots.

Try either importing sprites with "use room bg" set to "yes", or just set these colours gamewide also (if you don't need bgs to have different colours anyway you actually do not need to have bg slots).

arj0n

Finally I got it working!

When the sprites and the backgrounds all use the same 4-color palette one would think to setup the ags colour panel palette to be used for both the sprites and backgrounds, having only 4 slots needed for the 4 game colors.
But ags colour slot #0 (which must be black) seems to be problematic for sprites but works fine for backgrounds when switching its color codewise.
So you'll end up having 2 sets of identical slots color-wise, the first set is set to background, the 2nd one is set to gamewide.
(i had these 2 sets set up the other way around. which works fine except for slot #0 not changing for the sprites)
So slots #0-3 set to background and (for example) slots #16-19 set to gamewide in combination with importing the sprites using RemapToGamePalette = yes was the solution.
(of course code-wise you'll need to switch the background and the sprites separated since they are 2 sets now instead of 1)

So, to sum it all up:

  • File - Preferences: Remap palette of room backgrounds into allocated background palette slots (8-bit games only) = unchecked
  • colour-panel: slot #16-#19 are set to gamewide,
  • colour-panel: slot #0-3 are set to background,
  • colour-panel: both slot sets use the exact same colors (black, cyan, magenta, white)
  • sprite import - RemapToGamePalette = yes
  • sprite import - RemapToRoomPalette = no
  • sprite import - the tranparent color can be anything, it has obviously no influence for the colour panel layout
  • code: run UpdatePalette for bot slot sets

Result:
(switched from cga palette to game boy palette)

arj0n

One last question:

Currently when switching palette, all the sprites are switch from palette over the whole game, while only the current room background is switched.
It would be nice if I don't need to switch the palette for the background each time the player enters another room...

So:
Is it - outside the 'workaround' option of using an object and sprite as background - somehow possible to let the backgrounds act as being set 'gamewise' instead of 'background'?
I do need to keep the first 4 slots being set as background and the second set of 4 slots as being gamewide to avoid the sprites black color not switching correctly.



eri0o

I have no palette experience, but you can use event handles in a script module to deal with room leave and entering:

Code: ags

void on_event (EventType event, int data) {
  if(event == eEventEnterRoomBeforeFadein) {
    // Before fade in (room_Load)
  } else if(event == eEventLeaveRoom) {
    // On Leave
  }
}


https://adventuregamestudio.github.io/ags-manual/Globalfunctions_Event.html#on_event

arj0n


SMF spam blocked by CleanTalk