Page 1 of 1
How to draw a lot of objects fast in limited area?
Posted: Thu Dec 24, 2015 8:35 am
by Spessman
Hello there.
I have map 100x100 tiles. I'm limited tiles to draw for 15x15 tiles and do it trough Tile.contents (this table contains objects on tile) layer by layer. I'm also constantly moving...
But i have some problems. Objects with free per-pixel coordinates and i don't want to bind they to tiles.
So, how i can draw objects without .contents and do it fast, without spritebatch? On one map might be over of 10000 objects and they position is randomly, but we have some tables with it.
Re: How to draw a lot of objects fast in limited area?
Posted: Thu Dec 24, 2015 1:25 pm
by rmcode
Why don't you want to use a spritebatch?
So if I understand correctly your map is limited to 15x15 tiles, but your objects are placed "freely" (not on a grid) and therefore you can't limit their drawing?
You could probably check wether an object is offscreen by doing some simple coordinate checks.
Re: How to draw a lot of objects fast in limited area?
Posted: Thu Dec 24, 2015 2:57 pm
by Spessman
Why don't you want to use a spritebatch?
It's too cumbersome for me. And spritebatch need to update for a time i think. Therefore best way for me - direct draw
You could probably check wether an object is offscreen by doing some simple coordinate checks.
In area 8000-10000 objects. How i can do it fast without spritebatch? Or spritebatch is only one method?
Re: How to draw a lot of objects fast in limited area?
Posted: Thu Dec 24, 2015 3:12 pm
by rmcode
In area 8000-10000 objects. How i can do it fast without spritebatch? Or spritebatch is only one method?
Well it depends ... you should run a profiler and check where your game spends the most time.
Each time you draw something on the screen with love.graphics.draw you send some information (image, position, etc.) to the GPU. This is no problem when you just want to draw a few things each frame, but the more objects you draw the slower it becomes (even if all you objects use the same image). The spritebatch is basically a way to send one image to the GPU and tell it all locations where this particular image needs to be drawn.
So if you want fast drawing you probably won't get around the SpriteBatch.
Re: How to draw a lot of objects fast in limited area?
Posted: Thu Dec 24, 2015 3:37 pm
by slime
Even if you clear and re-add everything to a SpriteBatch every frame, it'll still be much more efficient than love.graphics.draw(image) in a loop.