Page 2 of 2

Re: Efficiently drawing a grid map

Posted: Sun Apr 18, 2021 1:53 pm
by Gunroar:Cannon()
So I could make an atlas of all the tiles used using imagedata, then sort it(?) and then use the sprite batch
...
how? :)

Re: Efficiently drawing a grid map

Posted: Sun Apr 18, 2021 3:52 pm
by darkfrei
Gunroar:Cannon() wrote: Sun Apr 18, 2021 1:53 pm So I could make an atlas of all the tiles used using imagedata, then sort it(?) and then use the sprite batch
...
how? :)
I've made such spritesheet and used sprites (quads) from it:
https://love2d.org/forums/viewtopic.php?f=3&t=90857

Re: Efficiently drawing a grid map

Posted: Sun Apr 18, 2021 5:37 pm
by Gunroar:Cannon()
??Hmmm... Do you get the pictures individually and then put them in one image data, using the data as a spritsheet for a sprite batch? Because that's what I'm asking for.

Re: Efficiently drawing a grid map

Posted: Sun Apr 18, 2021 6:24 pm
by pgimeno
No idea of how your project is structured. But you mentioned a grid, so I imagine that the images to draw in that grid are all of the same size. Create an image whose sides are multiples of the horizontal and vertical size respectively, of the images to include, that is able to fit all the images. Then place each image in the big one, allocating a quad at the same time, e.g. in left-to-right order then the next row and so on. Not sure what's complicated about it.

Finally, instead of drawing images, you draw quads of the big image. Or build a spritebatch, your call. Again, hard to know what's best with just the given info.

If your images are of varied sizes, there are algorithms for creating texture atlases automatically. The idea is the same, except for the row-by-row part. I think there have been libs posted in this forum too. Search.

Re: Efficiently drawing a grid map

Posted: Sun Apr 18, 2021 11:06 pm
by Gunroar:Cannon()
They are of the same size, thnx pgimeno, though can't I order it when the map is loaded, if it's just one big map, then just put it into an imagedata(what's up with me and imageData :crazy: )

Re: Efficiently drawing a grid map

Posted: Mon Apr 19, 2021 6:50 pm
by milon
pgimeno wrote: Sat Apr 17, 2021 10:56 am A texture atlas is the way to speed it up. SpriteBatch is made mostly for this kind of usage, and requires a texture atlas.
I thought sprite batching became automatic in Love a few versions ago? Am I mistaken about what that meant?

Re: Efficiently drawing a grid map

Posted: Mon Apr 19, 2021 7:07 pm
by pgimeno
milon wrote: Mon Apr 19, 2021 6:50 pm I thought sprite batching became automatic in Love a few versions ago? Am I mistaken about what that meant?
I mention that later on.
https://love2d.org/forums/viewtopic.php ... 86#p240186

Manual batching is still available. As I mention in that post, I'm not sure whether it improves performance or not.

Re: Efficiently drawing a grid map

Posted: Mon Apr 19, 2021 8:27 pm
by milon
pgimeno wrote: Mon Apr 19, 2021 7:07 pm
milon wrote: Mon Apr 19, 2021 6:50 pm I thought sprite batching became automatic in Love a few versions ago? Am I mistaken about what that meant?
I mention that later on.
https://love2d.org/forums/viewtopic.php ... 86#p240186

Manual batching is still available. As I mention in that post, I'm not sure whether it improves performance or not.
Note to self: Get better at reading, lol :crazy:
Thanks!

Re: Efficiently drawing a grid map

Posted: Tue Apr 20, 2021 11:44 am
by DrNefario
You could draw the whole map to a canvas, and then just draw the canvas each frame. The problem there would likely be texture size, depending on how big your map is. Or you could draw a screenful to a canvas, or slightly more than a screenful to give you a bit of scrolling before you need to redraw.

If you really want to use ImageData rather than Canvas, you can generate ImageData from a Canvas. I'm new to Love myself, so I don't totally understand what the advantages are.

Re: Efficiently drawing a grid map

Posted: Tue Apr 20, 2021 5:52 pm
by Gunroar:Cannon()
DrNefario wrote: Tue Apr 20, 2021 11:44 am You could draw the whole map to a canvas, and then just draw the canvas each frame. The problem there would likely be texture size, depending on how big your map is. Or you could draw a screenful to a canvas, or slightly more than a screenful to give you a bit of scrolling before you need to redraw.

If you really want to use ImageData rather than Canvas, you can generate ImageData from a Canvas. I'm new to Love myself, so I don't totally understand what the advantages are.
Thnx, that's a nice approach. I'll try it.