So im trying to switch the alternate color pallet back and forth every second with this code.
function _draw() pal(8,128+8,flr(time()%2)) end |
At first it has light red then waits a second and flips to the dark red, as expected, but then it just stays in the darker red and doesn't flip back for the second time..
All help greatly appreciated!
Till someone explains the third prameter of pal(1st,2nd,3rd) better, you need to swith the colors back. The 3rd parameter just changes if it is just drawn in an other color, or the palette changes even in the game editor.
But I still don't get it too...
function _draw() cls() for i = 1,15 do rectfill(8*i,8*i,8*i+8,8*i+8,i) end if flr(time()%2) == 0 then pal(8,128+8,1) else pal(128+8,8,1) -- or just -- pal() resets the colors to default end print(flr(time()%2)) end |
The third parameter changes what type of palette it modifies. Setting the third parameter to 0, or leaving it out, will remap the pixels you draw to the screen buffer, and setting it to 1 will change what colour the values in the screen buffer are interpreted as.
@Zellente :
Your solution works, but it's based on a misunderstanding :
pal(index,value,palette_number)
There are three palettes :
palette 0 or display palette (16 entries)
The values are what will be written in the video memory when the palette is used. Because each pixels is a 4 bit value in the video memory, the valid range of values is 0-15, other bits are ignored.
Likewise, the index range is 0-15 (16 palette entries).
palette 1 or display palette contains color numbers.(in the 0-255 range, but only 32 distinct colors). It is used to know what color represents each of the 16 possible values of pixels in the video memory.
Palette 2 or secondary palette is similar to palette 1 : it is 16 entries (0-15) of color numbers (0-255) that get used in special video modes that can be activated with pokes. In default display mode, it does nothing.
pal(128+8,8,1) ignores the highest bits of the index parameter, but it so happens that 128+8 & 0x0F is 8, and pal(8,8,1) is what was needed :
pal(8,128+8,1) says that pixels of value 8 are shown as dark red (color 136)
pal(8,8,1) says that pixels of value 8 are shown as red (color 8)
@maybdev, your one liner pal would be
pal(8,flr(time())%2==0 and 8 or (128+8),1)
[Please log in to post a comment]