benhumphreys [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=11859 Draw a sprite as a repeating texture <p>I'm new to Pico-8 and this is my first snippet. I would appreciate any feedback, or ways of making this more efficient.</p> <p>It's a snippet to draw a sprite in an area as a repeating pattern texture.</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> function drawpattern(idx, x0, y0, x1, y1) local sprx = 8 * (idx % 16) local spry = 8 * flr(idx/16) for y=y0,y1,8 do local endy = min(y1, y+8) local sampleh = endy-y for x=x0,x1,8 do local endx = min(x1, x+8) local samplew = endx-x sspr(sprx, spry, samplew, sampleh, x, y, samplew, sampleh) end end end </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> https://www.lexaloffle.com/bbs/?tid=29975 https://www.lexaloffle.com/bbs/?tid=29975 Sun, 24 Sep 2017 07:43:55 UTC