## Efficiently drawing a grid map

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Gunroar:Cannon()
Party member
Posts: 263
Joined: Thu Dec 10, 2020 1:57 am

### Re: Efficiently drawing a grid map

So I could make an atlas of all the tiles used using imagedata, then sort it(?) and then use the sprite batch
...
how?
Check out Treaty
me: I don't always code but when I do it's done flawlessly.
also me:

Code: Select all

 function Gunroar:Cannon()
for x, enemy in ipairs(self.allEnemies) do
self:Cannon(enemy)
end
end

Code: Select all

Lua Error: [file Gunroar.lua]:18: C stack overflow

darkfrei
Party member
Posts: 217
Joined: Sat Feb 08, 2020 11:09 pm

### Re: Efficiently drawing a grid map

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?
https://love2d.org/forums/viewtopic.php?f=3&t=90857
Gunroar:Cannon()
Party member
Posts: 263
Joined: Thu Dec 10, 2020 1:57 am

### Re: Efficiently drawing a grid map

??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.
Check out Treaty
me: I don't always code but when I do it's done flawlessly.
also me:

Code: Select all

 function Gunroar:Cannon()
for x, enemy in ipairs(self.allEnemies) do
self:Cannon(enemy)
end
end

Code: Select all

Lua Error: [file Gunroar.lua]:18: C stack overflow

pgimeno
Party member
Posts: 2610
Joined: Sun Oct 18, 2015 2:58 pm

### Re: Efficiently drawing a grid map

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.
Gunroar:Cannon()
Party member
Posts: 263
Joined: Thu Dec 10, 2020 1:57 am

### Re: Efficiently drawing a grid map

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 )
Check out Treaty
me: I don't always code but when I do it's done flawlessly.
also me:

Code: Select all

 function Gunroar:Cannon()
for x, enemy in ipairs(self.allEnemies) do
self:Cannon(enemy)
end
end

Code: Select all

Lua Error: [file Gunroar.lua]:18: C stack overflow

milon
Party member
Posts: 123
Joined: Thu Jan 18, 2018 9:14 pm

### Re: Efficiently drawing a grid map

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?
pgimeno
Party member
Posts: 2610
Joined: Sun Oct 18, 2015 2:58 pm

### Re: Efficiently drawing a grid map

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.
milon
Party member
Posts: 123
Joined: Thu Jan 18, 2018 9:14 pm

### Re: Efficiently drawing a grid map

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
Thanks!
DrNefario
Prole
Posts: 5
Joined: Thu Apr 08, 2021 7:44 pm

### Re: Efficiently drawing a grid map

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.
Gunroar:Cannon()
Party member
Posts: 263
Joined: Thu Dec 10, 2020 1:57 am

### Re: Efficiently drawing a grid map

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.
Check out Treaty
me: I don't always code but when I do it's done flawlessly.
also me:

Code: Select all

 function Gunroar:Cannon()
for x, enemy in ipairs(self.allEnemies) do
self:Cannon(enemy)
end
end

Code: Select all

Lua Error: [file Gunroar.lua]:18: C stack overflow


### Who is online

Users browsing this forum: No registered users and 30 guests