can someone explain to me how to get a sprites bounding box?
I have this code which reads from the center of a sprite and keeps checking above it until the pixel is 0 or its at the top of the sprite.
function boxt(s,x,y,w,h) local sx1=flr(s%16)*(w*8) local sy1=flr(s/16)*(h*8) local sx2=sx1+(w*8) local sy2=sy1+(h*8) local cx =4 local cy =4 //find 0 pixel or top while sget(sx1+cx,sy1+cy) != 0 or sy1+cy > sy1 do cy-=1 end sspr(sx1,sy1,sx2-sx1,sy2-sy1,x+cx,y+cy) return cy+y end
however it doesn't seem to work
local s,x,y=22,63,63 function _draw() cls(1) if(boxt(s,x,y,1,1) > 0) then y-=1 end //spr(s,x-4,y-4) end
Sprites don't really have a bounding box, per se. It's all just memory locations. The sprite number just indicates to PICO-8 where to start getting sprite data from the sprite sheet data in memory.
spr() allows you to give a simple sprite number and it figures out where in the sprite sheet to start getting an 8x8 chunk of memory. sspr() allows you to specify any arbitrary position to start getting sprite data and any arbitrary size of data to then get starting at that position.
[Please log in to post a comment]