Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(2 edits)

Thanks a real lot for your time in this alrado. I really appreciate and that is exactly what I was referring to.

However I do not think I am understanding the technique you used.

In the FG I see 5 sprites with pixels of all colours. What are those? When I removed them and ran the cartridge, nothing was displayed.

And you used the BG to draw your sprites. Why?

I guess if you use the sprite editor, you are still limited to 256 sprites and 256 tiles right? How does this give us 512 sprites instead of 256?

And why are there 2 sets of sprites on screen? It is as if the whole BG area is being output as well and then the sprite at 50,50.

Excuse my lack of experience in this but I am asking to learn.

If you can find some time to add a little more comments, that would be great.

Thanks once again for your time and well done for the cartridge.

My example does the following:

1. I have a painted sprite the size of 4x3 cells, it is drawn in BG.

I put it on the screen at position 0,0. The rest of the space BG and FG is empty.

2. Now I read 2-bit pixel values from the screen, combine two values into one 4-bit value and save it in a table

3. I write down all the values from the received table into memory. For clarity, I wrote them down in the FG area, but this area can be any.

4. Now I show how you can display a 2-bit image.

Also, for clarity, I used the palette of the 2-bit CGA palette

Here you can see the animation

-- title: 2-bit sprite
-- author: Al Rado
-- desc: shows how convert native TIC-80 4-bit sprite to 2-bit
-- script: lua
-- input: gamepad
-- pal: 00000000ffffff00ffffffff000000000000000000000000000000000000000000000000000000000000000000000000

SPRITE_ADDR=0x4000*2
NIBBLES_IN_SPR=64
SPR_IX=256
ADDR=SPRITE_ADDR+NIBBLES_IN_SPR*SPR_IX

SPR_W=4*8
SPR_H=3*8

-- convert native sprite to 2-bit sprite and save to memory
cls()
spr(0,0,0,-1,1,0,0,4,3)

local nibbles={}
for i=0,SPR_W*SPR_H-1 do
 nibbles[#nibbles+1]=pix(i%SPR_W,i/SPR_W) 
end

for i=1,#nibbles,2 do
 local first=nibbles[i] << 2
 local second=nibbles[i+1]
 poke4(ADDR+i//2, first+second) 
end

-- draw 2-bit screen from memory
local posX=50
local posY=50
for i=1,SPR_W*SPR_H,2 do
 local val=peek4(ADDR+i//2)
 local first=val >> 2
 local second=val - (first << 2)
 pix(posX+(i-1)%SPR_W,posY+(i-1)/SPR_W,first)
 pix(posX+(i)%SPR_W,posY+(i)/SPR_W,second)
end

function TIC()
 -- not implemented
end