Hi friends, I'm wondering in which situations I should use canvas, it will be easier if you show me some examples in games.
For example, I read in the wiki By drawing things that do not change position often (such as background items) to the Canvas.
In this case, the background could be a canvas and the health bars, but what about the characters, should they be in a canvas too? and the particles like throwing things?
should I use canvas
Re: should I use canvas
Drawing a bitmap on screen is fast. No need to use a canvas. Drawing complex things can be slow. Use a canvas if you need to draw complex things more than once per frame.
Are they slow to render? Do you draw them more than once per frame? If yes, use a canvas. If no, don't.
A particle system is the epitome of a thing that changes often. Just apply the basic logic that is outlined aboved and in the Wiki you mentioned.
Re: should I use canvas
Just a small question for grump.
Could you give an example of what things would be slow to render? I have just started and I'm just using PNG images for my sprites. Are these rendered in constant time or what factors influence the rendering?
I am just starting out and the only thing I am drawing to Canvas at the moment is the tiles that compose the background.
Could you give an example of what things would be slow to render? I have just started and I'm just using PNG images for my sprites. Are these rendered in constant time or what factors influence the rendering?
I am just starting out and the only thing I am drawing to Canvas at the moment is the tiles that compose the background.
Re: should I use canvas
Things that require multiple passes to draw, or lots of draw calls. The font generator that is linked in my signature has effect combinations that need to draw each character like 8-10 times with complex shaders to compute distance fields, normal maps, etc. It takes up to several hundred milliseconds to render a complete font; it makes sense to render it one time onto a Canvas and use the resulting image to draw actual text with, which takes almost no time.
GPUs are really good at pushing pixels fast. What takes time is drawing many different things and/or using complex shaders. There is no benefit using a canvas to draw simple sprites, since they're technically the same thing.I have just started and I'm just using PNG images for my sprites. Are these rendered in constant time or what factors influence the rendering?
Re: should I use canvas
I would recommend using canvases for things like backgrounds, but, as grump said, mostly only for complex drawings and other slow rendering processes.
For example, in one of my projects I create a tile-based map with a simple table of tile-ids, and so each tile must be drawn at a different position several times, then added the first layer of non-ground tiles (like trees and such), then the second and third, and finally the layer of squares that will be the visible grid. The whole process hits the system with a whopping damage of a fps drop from 60 to 5, so, naturally, I added a reload button and started drawing the whole thing once in a canvas, which kept it at 58fps in the worst cases, and instantaneous most of the time!
I hope this example helps in the decisions of when to make canvases, good luck!
For example, in one of my projects I create a tile-based map with a simple table of tile-ids, and so each tile must be drawn at a different position several times, then added the first layer of non-ground tiles (like trees and such), then the second and third, and finally the layer of squares that will be the visible grid. The whole process hits the system with a whopping damage of a fps drop from 60 to 5, so, naturally, I added a reload button and started drawing the whole thing once in a canvas, which kept it at 58fps in the worst cases, and instantaneous most of the time!
I hope this example helps in the decisions of when to make canvases, good luck!
function earth:destroy()
00count=5000
00while count>0 do
0000lg.draw(explosion,math.random(0,600),math.random(0,800))
0000count=count-1
00end
00earth = nil
00print("Earth has been destroyed.")
end
00count=5000
00while count>0 do
0000lg.draw(explosion,math.random(0,600),math.random(0,800))
0000count=count-1
00end
00earth = nil
00print("Earth has been destroyed.")
end
Who is online
Users browsing this forum: Bing [Bot] and 2 guests