Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

TIC-80

Fantasy computer for making, playing and sharing tiny games. · By Nesbox

sget function to read pixels from sprite memory?

A topic by 10c8 created Feb 10, 2017 Views: 771 Replies: 2
Viewing posts 1 to 2

How exactly do I read pixels from the sprite memory? I can't figure out the math needed to convert the X,Y to the correct pixel location in the sprite memory.

Developer (1 edit) (+1)

The spritesheet isn't a 128x128 image in the memory, it's 256 consecutive 8x8 4 bit sprites

So, to set/get pixels to the spritesheet try to use these functions

function sset(x,y,c)
    local addr=0x4000+(x//8+y//8*16)*16 -- get sprite address
    poke4(addr*2+x%8+y%8*8,c) -- set sprite pixel
end
function sget(x,y)
    local addr=0x4000+(x//8+y//8*16)*16 -- get sprite address
    return peek4(addr*2+x%8+y%8*8) -- get sprite pixel
end

edit:

added the functions to snippets https://github.com/nesbox/tic.computer/wiki/Code-examples-and-snippets#setget-spritesheet-pixel

Thank you! Btw awesome work on this project!