love.draw and adding images constantly

General discussion about LÖVE, Lua, game development, puns, and unicorns.
hatethinkingofnames
Prole
Posts: 4
Joined: Sat Jul 20, 2013 4:42 am

love.draw and adding images constantly

Post by hatethinkingofnames »

Hello friends,

I'm a little confused. Or I might be retarded, so bear with me. I come from Corona so my Lua way of thinking is a little different. In corona you dont have to draw your image to the screen, which makes me wonder. Do all languages have to 'draw' the images to the screen after you've added it, except most engines just do it behind the scenes so you don't have to worry about it? Or is this a LOVE specific thing?

My main question being, how are you guys loading up images AFTER your initial load? Since if you call function love.draw after the initial load it will remove everything else drawn and only draw what you last requested. Let's say a tower defense that has 10 different towers shooting multiple projectiles every second. Are you supposed to keep 3-10 projectiles hidden for each tower and call them when the tower attacks? And instead of removing them you hide them again and just change position for them like that non-stop?

The wiki says it draws every frame? That sounds a little scary, which makes me wonder again, are all engines like this where they just do it behind the scenes so you dont know/have to think about it? Quite interesting. So are you guys creating your own groups of images like:

Code: Select all

stuff = {}
stuff[1] = love.graphics.newImage( "what.png" )
stuff[2] = 100
stuff[3] = 100

what = {}
what[1] = love.graphics.newImage( "what.png" )
what[2] = 200
what[3] = 200

images = { stuff, what }

function love.draw()
    for i = 1, #images do
			love.graphics.draw( images[i][1], images[i][2], images[i][3])
	end
end
So is a very graphic intensive game possible? Something with tons of projectiles like a tower defense or a bullet storm game? I actually saw a bullet storm demo I believe but I'd assume he's using particles or something? Anyway, any info is very much appreciated on the subject and how things work. Thanks in advance
User avatar
adnzzzzZ
Party member
Posts: 305
Joined: Sun Dec 26, 2010 11:04 pm
Location: Porto Alegre, Brazil

Re: love.draw and adding images constantly

Post by adnzzzzZ »

hatethinkingofnames wrote:Do all languages have to 'draw' the images to the screen after you've added it, except most engines just do it behind the scenes so you don't have to worry about it? Or is this a LOVE specific thing?
Engines that do it behind the scenes are doing something similar to what is happening with LÖVE, they just hide it behind another layer of abstraction. With love you just create an Image object, store it in a variable and then use that to draw to the screen whenever you want.
hatethinkingofnames wrote:My main question being, how are you guys loading up images AFTER your initial load? Since if you call function love.draw after the initial load it will remove everything else drawn and only draw what you last requested. Let's say a tower defense that has 10 different towers shooting multiple projectiles every second. Are you supposed to keep 3-10 projectiles hidden for each tower and call them when the tower attacks? And instead of removing them you hide them again and just change position for them like that non-stop?
You can just reuse the same image for all different projectiles. In your example you have just used stuff or what instead of both of them and the result would have been the same. The image is something separate from whatever else you have going on, since the draw call will simply draw that image at the specified x, y position.
hatethinkingofnames wrote:So is a very graphic intensive game possible? Something with tons of projectiles like a tower defense or a bullet storm game? I actually saw a bullet storm demo I believe but I'd assume he's using particles or something?
Usually you can get away with doing it normally, but there are many different ways to use LÖVE's drawing system (that I'm sure other people will be able to explain!) to achieve high draw counts.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: love.draw and adding images constantly

Post by raidho36 »

Vast majority of engines require you to manually render your stuff, Corona is marginal case here and I honestly hate how it's autorendering works.

You just render your stuff sequentially, and it's added one on top of another (unless certain blend mode specified).

Code: Select all

draw ( background, 0, 0 )
for objects do
    draw ( o.sprite, o.x, o.y )
end
draw ( gui, 0, 0 )
Also, no offence, this is very vibrant example of what happens when people are starting game programming without proper programming knowledge base. I don't honestly think you're even know what you're doing because, you know, your're asking for explaining you that basic things.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: love.draw and adding images constantly

Post by Plu »

Don't worry, computers are very powerful and the graphics card handles most of the intense graphic action.

It's important to note that you only need to load an image once, but you can draw as many copies as you like. So you don't need to preload a bunch of bullet images; you just load the bullet image once and then draw a whole bunch of copies by making multiple calls to love.graphics.draw() with the bullet image as the first argument.

Game engines that allow you to select an image for an object also just load it once and then redraw the same image multiple times, they just abstract away that they're doing it. So yeah, graphics intense stuff is certainly possible and easy, as long as you only load each image once and reuse the variable.

And yeah, love.draw is called every frame, so just make sure you keep drawing all the stuff that needs to be on the screen in the right place. Worry about performance only when it starts dropping, LÖVE can handle a few hundred entities without any problems even with poorly performing code.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: love.draw and adding images constantly

Post by T-Bone »

If you feel that you're doing a lot of redundant drawing each frame, you should also check out canvases and spritebatches, they allow you to render something once to a buffer. Then all you have to do each love.draw is to draw the entire buffer which will be faster. Doing this makes sense for things that don't change often (like the background, a static world made from tiles etc).
User avatar
MPQC
Citizen
Posts: 65
Joined: Fri Jun 28, 2013 2:45 pm

Re: love.draw and adding images constantly

Post by MPQC »

From the example you gave about bullet hell, you can do them. The demo I posted on it only supports a few hundred bullets on the screen on a pretty good computer, but I rewrote it so it can support thousands (images, not particles). You'll most likely have no issues at all with a tower defense either. Everything else was covered by others above. :)
hatethinkingofnames
Prole
Posts: 4
Joined: Sat Jul 20, 2013 4:42 am

Re: love.draw and adding images constantly

Post by hatethinkingofnames »

Wanted to stop by and thank everyone for sharing their knowledge, it's really appreciated. I'm currently doing some benchmarks on multiple frameworks. If i'm not to lazy to put the results in a graph and make it all pretty I'll post the info. Thanks once again for your help
User avatar
MPQC
Citizen
Posts: 65
Joined: Fri Jun 28, 2013 2:45 pm

Re: love.draw and adding images constantly

Post by MPQC »

hatethinkingofnames
Prole
Posts: 4
Joined: Sat Jul 20, 2013 4:42 am

Re: love.draw and adding images constantly

Post by hatethinkingofnames »

I've actually seen that one. Unfortunately Love did get pretty sad benchmarks compared to the rest, although if you look way at the bottom of the comments someone edited the source code and made Love do 85k sprites compared to the 5-6k the thing had. Also using LuaJit someone went 9k but can't use that one as much since different PC specs. I'm curious as how they got 85k, did they edit the source code just for sprites and to get a crazy benchmark? Would be cool if slime or shell32 I think it was explained a little more.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: love.draw and adding images constantly

Post by raidho36 »

I'm curious as how they got 85k
Spritebatch? Yep, it's all as simple as that.*

*and FFI
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests