
a little function i wrote for fun ...! it lets you draw a sprite as if it was a rectangle :]
works best when the sprite is evenly divisible by 3 both ways ... but it will not cause any errors if that isn't the case
i could certainly make the code smaller, but i feel like working on other things at the moment, so you can have it as it currently is 🤲
function sprrect(x, y, w, h, s) s = get_spr(s) local slice_w, slice_h = s:attribs() slice_w = slice_w\3 slice_h = slice_h\3 local slices = {} -- split into 3x3 slices for _y = 0,2 do local row = {} for _x = 0,2 do local slice = userdata("u8", slice_w, slice_h) s:blit(slice, _x*slice_w,_y*slice_h,0,0, slice_w, slice_h) add(row, slice) end add(slices, row) end -- draw corners spr(slices[1][1], x - slice_w, y - slice_h) spr(slices[1][3], x + w, y - slice_h) spr(slices[3][1], x - slice_w, y + h) spr(slices[3][3], x + w, y + h) -- draw edges ---- top clip(x, y - slice_h, w, slice_h) for _x = 0, w, slice_w do spr(slices[1][2], x + _x, y - slice_h) end ---- bottom clip(x, y + h, w, slice_h) for _x = 0, w, slice_w do spr(slices[3][2], x + _x, y + h) end ---- left clip(x - slice_w, y, slice_w, h) for _y = 0, h, slice_h do spr(slices[2][1], x - slice_w, y + _y) end ---- right clip(x + w, y, slice_w, h) for _y = 0, h, slice_h do spr(slices[2][3], x + w, y + _y) end -- draw center clip(x, y, w, h) for _x = 0, w, slice_w do for _y = 0, h, slice_h do spr(slices[2][2], x + _x, y + _y) end end clip() end |
[Please log in to post a comment]