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.


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

P#110822 2022-04-25 11:41

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 ▽ | Forks ▽ | No License

P#110876 2022-04-26 05:47 ( Edited 2022-04-26 18:53)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2022-09-25 23:06:50 | 0.007s | Q:12