Log In  


Hey, is there a way to draw a rectangle of arbitrary dimension filled with tiled sprites, aka textured rectangle or tiled rectangle? I can of course manually iterate and draw the same sprites many times, but this had very bad performance so I quickly hit over 1 CPU (meaning I'm dropping from 60 to 30 FPS).

In other engines, you'd set sprite rendering mode to Tiled and stretch the sprite, resulting in a repeating pattern preserving the sprite original size, instead of stretching the original sprite like sspr.

Recently, we got textured lines (tline) and fill patterns (fillp) but there is no direct way to use them to draw tiled sprites.

I see some ways to do that, but they are all workarounds, with no one-line solution:
a. iterate on 2D coordinates and draw same sprite with spr() -> bad performance
b. prepare a tilemap of the same sprites and draw them, offset by some camera() with map() -> need to either setup tilemap in data or generate them at runtime, and need to think with reverse offset to set camera properly. Kind of a waste of data if your rectangle is always using the same sprite. Only works if you have spare space in your tilemap (or you must overwrite some tilemap data and restore it later; note that with Big Maps in PICO-8 0.2.4, it's less of an issue)
c. use fillp to set up a binary pattern and use it for rectfill -> only works for binary (2-color) sprites

I'm using a. for now, and only drawing sprites visible by at least 1px on screen to spare CPU, but even that costs too much (around 0.7 out of my budget of 0.1! and I need TWO layers of those because the foreground layer has some transparency, so I quickly get over CPU budget).

I think I'll be switching to b. for now.

Suggestion:

sspr() could have an additional argument "render_mode_option". 0 is default of stretching, 1 is for tiled rendering.

1


1

see tline - this is exactly doing that (1 line at a time, so at least need to iterate over height)

Cart #repibohigu-0 | 2022-04-26 | Code ▽ | Embed ▽ | No License
1


Thanks, this can go as long as I have some map space free to use. It will work in my case as this particular cart is not using the map at all. Otherwise, I suppose I'd need to either reserve some map space, or temporarily move map content away to gain some temporary space, then move the original content back.

A generic textured tile/sprite function would still be helpful for quick usage, I should consider this for suggestion.

UPDATE: looks like I also need a power of 2 number of cells in width and height, but I need 6x4 tiles repeat. I suppose drawing with map() will be easier in this case.



[Please log in to post a comment]