First of all, sorry my bad english, i'm from Brazil...
Well, my problem is:
when i draw multiple images with a loop(like from zero to 600), my game still slow, the character moves slow.
Are there some solution for it?
See the video(very low quality)
[SOLVED]Draw order affecting speed
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[SOLVED]Draw order affecting speed
- Attachments
-
- RpgProject.love
- Solved
- (495.58 KiB) Downloaded 205 times
Last edited by Featzen on Fri Jul 10, 2015 5:05 am, edited 1 time in total.
Re: Draw order affecting speed
Hi and welcome to the forum!
You are correct: Drawing many images can make a game slow, but there are some methods to speed it up. As a rule of thumb, try to minimize the number of "love.graphics.draw"-calls. Every time you call it, LÖVE has to communicate with the graphics card and that takes some time.
For speeding your game up, try to use a spriteBatch. With it you can draw many images with only one draw-call. Have a look at this tutorial for an introduction.
You are correct: Drawing many images can make a game slow, but there are some methods to speed it up. As a rule of thumb, try to minimize the number of "love.graphics.draw"-calls. Every time you call it, LÖVE has to communicate with the graphics card and that takes some time.
For speeding your game up, try to use a spriteBatch. With it you can draw many images with only one draw-call. Have a look at this tutorial for an introduction.
Check out my blog on gamedev
- Positive07
- Party member
- Posts: 1014
- Joined: Sun Aug 12, 2012 4:34 pm
- Location: Argentina
Re: Draw order affecting speed
Other enhancements:
1- If you need to refresh every single frame (for example the background is randomly generated/animated and made of tiles), try to lower the number of draw calls by just drawing what is inside of the screen and not drawing what is outside of it.
2- If the level is completely static (the tiles dont change) you can use a [wiki]Canvas[/wiki] as an alternative to Sprite Batches (or a combination of both if you are clever enough)
3- Reduce the amount of RAM consumed by your images, for example by using some compressed formats (there are a bunch, some of them lack some channels, like the alpha one, or have a limited amount of bits for each channel, say 6bits instead of the standard 8bits), another way to reduce the size of an image is by reducing the width and height.
4- This is linked to the above, many images consume more RAM than a single image containing all the sprites, this basically means you can use a sprite sheet and then use [wiki]Quads[/wiki] to draw each sprite to the screen (Also Quads work really nice with Sprite Batches, check [wiki]Spritebatch:add[/wiki] for more info)
5- Whenever you need something pretty standard like squares or circles try to use the primitive shapes LÖVE provides instead of an image of it (Unless the shape is part of a more complex shape and you can simple draw it in the same image)
And I guess that is it!
1- If you need to refresh every single frame (for example the background is randomly generated/animated and made of tiles), try to lower the number of draw calls by just drawing what is inside of the screen and not drawing what is outside of it.
2- If the level is completely static (the tiles dont change) you can use a [wiki]Canvas[/wiki] as an alternative to Sprite Batches (or a combination of both if you are clever enough)
3- Reduce the amount of RAM consumed by your images, for example by using some compressed formats (there are a bunch, some of them lack some channels, like the alpha one, or have a limited amount of bits for each channel, say 6bits instead of the standard 8bits), another way to reduce the size of an image is by reducing the width and height.
4- This is linked to the above, many images consume more RAM than a single image containing all the sprites, this basically means you can use a sprite sheet and then use [wiki]Quads[/wiki] to draw each sprite to the screen (Also Quads work really nice with Sprite Batches, check [wiki]Spritebatch:add[/wiki] for more info)
5- Whenever you need something pretty standard like squares or circles try to use the primitive shapes LÖVE provides instead of an image of it (Unless the shape is part of a more complex shape and you can simple draw it in the same image)
And I guess that is it!
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Re: Draw order affecting speed
Thank you both, i will read about spritebatch.
Love2d is beautiful :p
Love2d is beautiful :p
Re: Draw order affecting speed
Primitive shapes are shamefully slow though. You can use meshes to easily draw filled primitives like this:Positive07 wrote:5- Whenever you need something pretty standard like squares or circles try to use the primitive shapes LÖVE provides instead of an image of it (Unless the shape is part of a more complex shape and you can simple draw it in the same image)
Code: Select all
local segments = 50
local t = {{0,0,0,0}}
for i = 0, segments do
t[i+2] = {math.cos(math.pi*2/(segments)*i), math.sin(math.pi*2/(segments)*i),0,0}
end
t[#t+1] = t[2]
segments = segments+1
circle = love.graphics.newMesh(t)
circle:setVertexColors(false)
Code: Select all
love.graphics.draw(circle, x, y, 0, radius) -- 0 is the rotation, pretty useless on a circle, don't you think?
Code: Select all
rectangle = love.graphics.newMesh{0,0, 1,0, 1,1, 0,1, 0,0}
rectangle:setVertexColors(false)
--draw it like this:
love.graphics.draw(rectangle, x, y, rotation, width, height)
Last edited by Nixola on Wed Jul 08, 2015 11:17 am, edited 1 time in total.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
- Positive07
- Party member
- Posts: 1014
- Joined: Sun Aug 12, 2012 4:34 pm
- Location: Argentina
Re: Draw order affecting speed
You are right! In the case that you need an static shape (vertices dont change) you can use [wiki]Mesh[/wiki]es, they have the added benefit that you can place them wherever you want! You can even texture themNixola wrote:-snip-
But creating them is expensive so in that case primitive shapes may be better.
NOTE: If you are doing a simple shape and you just need to change the size you could scale it (rotate it, sheer it) though since those transformations dont affect the Mesh
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Re: Draw order affecting speed
@Nixola There is a small typo: "setVertexColors" instead of "setVertexColor"
Re: Draw order affecting speed
Right, I keep forgetting to update the repo where I got the snippets from, thanks!SiENcE wrote:@Nixola There is a small typo: "setVertexColors" instead of "setVertexColor"
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: Draw order affecting speed
I'm drawing images, now with spritebatch.
But i'm doing something wrong, what is?
Here, still 6 fps :s
But i'm doing something wrong, what is?
Here, still 6 fps :s
- Attachments
-
- RpgProject.love
- (495.53 KiB) Downloaded 168 times
-
- Prole
- Posts: 34
- Joined: Mon Nov 24, 2014 9:15 pm
Re: Draw order affecting speed
Mate,Featzen wrote:I'm drawing images, now with spritebatch.
But i'm doing something wrong, what is?
Here, still 6 fps :s
We're running at 60 over here! I think there might be a problem over your side ...
Who is online
Users browsing this forum: Google [Bot] and 2 guests