Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

TIC-80

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

Mask for Paint functions

A topic by hashalon created Mar 04, 2017 Views: 564 Replies: 3
Viewing posts 1 to 3

I was working on a little projet in TIC-80 and I came accross a problem:

I have a shape made of a circle and a rectangle and I would like to cut pieces of it.So my idea was to draw the shape and simply draw on top of it to remove parts of it. However if I do that, I cannot draw stuff behind of the shape.

So I was wondering if it could be possible to add an optional 'mask' parameter to each paint function:

line    x0 y0 x1 y1 color [mask]
rect    x y w h color [mask]
rectb   x y w h color [mask]
circ    x y radius color [mask]
circb   x y radius color [mask]
tri     x1 y1 x2 y2 x3 y3 color [mask]

So that the function would only draw on pixels of the color specified by the mask. It would be quite useful for demos.

But if it is too much for a machine that is supposed to be limited, I would like to have some hints on how to draw complex shapes. Like maybe there is a way to draw on the spritesheet and then draw back the sprite on the screen.

Developer(+1)

I think it's to much to add mask to the draw api.

So, I see the following workaround:

- draw all your complex shapes to the screen buffer using regular draw api;

- then copy part of the screen to the sprites buffer using 'pix' and 'sset' functions (https://github.com/nesbox/tic.computer/wiki/code-e...);

- clear the screen and finally you can draw your complex shapes from the sprites using 'spr' api :)

Thanks, I tried your solution and I noticed that there is a bug with the sset function (and surely with the sget function too)

It should be

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

and not

-- set spriteheet pixel
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
Developer (1 edit)

yes, this is a bug

and thanks for the fix :)