Best way to create a grid of sprites?

I’m trying to make a grid of sprites using a nested loop:

This works reliably[edit:] sometimes with the 0.03 seconds wait block. :frowning_face: But even then it’s slow. You can watch as it draws the individual sprites. Here’s what it looks like in a browser preview:

Thunkable (2)

It takes approximately 3 seconds to complete. With 49 sprites being created, that’s going to be a minimum of 1.47 seconds (49 * 0.03 = 1.47). That feels very slow for a game that needs to refresh the screen for new levels.

Does anyone have a fast, reliable way to create a grid of sprites?

I think something is wrong with my logic or something is wrong with the Canvas component.

If I add much longer delays, I still see positioning errors:

image

Even giving each Wait block a 1 second value (for a total of about 50 seconds!) results in positioning errors. Ack!

When I do this with a button instead (no Canvas), it works beautifully and immediately without any Wait blocks required:

image

It takes visibly no time at all to render the entire grid of buttons:

image

This leads me to believe that the problem is with the Canvas component and not with my logic.

1 Like

Is it necessary that it be with sprites? I think you could make a row of cells (buttons, columns or labels) and then save it as a Data view layout, in this way, depending on how many rows your database has, can you replicate the row in different rows?

It does have to be sprites. I decided to make a proof-of-concept for a tower defense game. I know that Thunkable is limited in terms of the games you can make but my first step is to figure out how to spawn the grid. That will allow me to generate mazes, allow the player to add towers, etc.

Part of the simplicity (good) of Thunkable is that each component is ideal for a specific task; part of the limitation (bad) of Thunkable is that each component is specialized so I can’t, for example, set the speed or position of a button using blocks. I can set the speed/position of a sprite but I can’t do sophisticated swipe/drag & drop detection with a sprite (or a button for that matter).

I’ve reported this Canvas issue here: Canvas processing is slow and unpredictable · Issue #1232 · thunkable/thunkable-issues · GitHub

1 Like