How to draw a lot of objects fast in limited area?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Spessman
Prole
Posts: 9
Joined: Sun Oct 11, 2015 2:19 pm

How to draw a lot of objects fast in limited area?

Post 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.
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: How to draw a lot of objects fast in limited area?

Post 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.
Spessman
Prole
Posts: 9
Joined: Sun Oct 11, 2015 2:19 pm

Re: How to draw a lot of objects fast in limited area?

Post 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?
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: How to draw a lot of objects fast in limited area?

Post 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.
User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: How to draw a lot of objects fast in limited area?

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 0 guests