Using the canvas?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
severedskullz
Prole
Posts: 36
Joined: Thu May 30, 2013 1:55 am

Using the canvas?

Post by severedskullz »

I'm hoping that this is the last technical question I will have regarding specific functions or portions of LOVE.

I saw the Canvas class and I was a bit confused about something it mentioned:
By drawing things that do not change position often (such as background items) to the Canvas, and then drawing the entire Canvas instead of each item, you can reduce the number of draw operations performed each frame.
Now I understand the concept of drawing to the 'texture' but what I don't understand is how each draw call affects performance. From what I am seeing is implied... more draw calls = slower. I would assume this doesn't really matter the size of the items either?

Would this be something I would be looking for in order to... say... draw a star field in the background consisting of 50K+ points? I am already doing so via a loop and table at a very nice 300 FPS, but would it save me C/GPU time in order to draw it to the canvas and draw the single canvas instead in each Draw state?

My next question is what would happen if we wish to update the canvas. Theoretically I could just create a new canvas, draw my items to it, and reassign it to the canvas variable. It is implied that the canvas acts as a texture and retains all image data on itself and does not need to be updated each frame. Is this correct?
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Using the canvas?

Post by Plu »

Yep, sounds correct to me. Making less draw calls means less overhead, and especially when you have overlapping items then pre-determining what the final layout is will matter a lot. So yeah, reducing the star field to a single canvas would help quite a bit.

And yes, you only need to draw once and the canvas will retain its image information. To change a canvas, you'll have to redraw the whole canvas one item at a time. An exception exists for if you just want to add more content to it.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests