Page 1 of 1

Like a spritebatch for vectors?

Posted: Wed Mar 02, 2016 8:26 am
by feelixe
Hey! I'm making a game with alot om lines and rectangles, like a 1000 of each. The only thing they do is strech in Y and X and move ofcourse. So i thought of a canvas to make it more efficent, but then it's not vectorized. So i thought of a spritebatch, but thats only for textures.

Is there anything like a spritebatch but only for rectangles and line? Would really help, thanks! :awesome:

Re: Like a spritebatch for vectors?

Posted: Wed Mar 02, 2016 8:59 am
by Nixola
You can use a 1x1 white texture and scaling/rotation when adding it to a spritebatch. For example, Spritebatch:add(0, 0, -math.pi/2, 256, 1) would create a line, 256 pixels in length, rotated by -pi/2.

Re: Like a spritebatch for vectors?

Posted: Wed Mar 02, 2016 9:18 am
by feelixe
Nixola wrote:You can use a 1x1 white texture and scaling/rotation when adding it to a spritebatch. For example, Spritebatch:add(0, 0, -math.pi/2, 256, 1) would create a line, 256 pixels in length, rotated by -pi/2.
Thank you, but if i then draw the spritebatch and scale it the lines will get pixelated, since it's not a true vector. Any fix for that?

Re: Like a spritebatch for vectors?

Posted: Wed Mar 02, 2016 10:05 am
by Nixola
I'd say scale the lines themselves when adding them to the batch instead of the whole spritebatch. I would try and come up with a demo or something (as well as testing it, as I am not completely sure it would work) but I currently can't.
P. S: clearing a spritebatch and putting everything back in it every frame is still faster than drawing each line separately with lg.rectangle.

Re: Like a spritebatch for vectors?

Posted: Thu Mar 03, 2016 6:38 am
by T-Bone
Maybe you could use meshes? I haven't been playing around much with those, so I'm not sure they'll solve your problem but they do let you preload shapes to the GPU which sounds like pretty much what you'd want to do.