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)
@RealShadowCaster Oh thanks! I understand it a bit more now, so the first value doesn't need to change?
@maybdev, you're right, the first value should stay in the 0-15 range since it's the index of the palette entry to change, and all three palettes are of
size 16 and start at index 0. In your exmaple, your index 8 din the display palette is always used for red, but you change the color used between two reds (color 8 and color 136). It's always index 8 that you are using for red in the example.
Second parameter (value) should be in the 0-15 range for palette 0 and 0-255 range for palettes 1 and 2.
If pal is called with out of range values, the extra set bits are ignored, and it gets trickier to figure out what's going on.
@RealShadowCaster thank you for all the input. Might reanimate some old code/carts to get into this pal() again.
@maybdev I'm new to this pico-8 and Lua. And I also tried to use more than 16 colors, but got stuck and gave up this part. But thanks to this "tool" random game idea generator and after a few runs, it gave a useable game idea and now I'm into btn(), arrays(tables), for-loops and all the other fun stuff of programming.
But to share some informations these posts I found kind of useful about pal() and using more than one color palette. Might help you with your project.
-
painto-8 lite. There is a cart that uses 2 color palettes and changes the screen colors.
I use this cart/code a lot, because you can just copy/paste it to the end of a cart and it works. -
And here is an old Post but the last entry is from 2024, that says it stll works and like in the middle is a cart with 32 colors on screen.
- I used this website for search for this poke/peek numbers.
antifandom
[Please log in to post a comment]