Stencils with fixed content
Posted: Wed Sep 26, 2012 5:40 pm
Dear Community,
I am currently working on an isometric game. As I am working on an older machine, I am concerned about performance. I figured that, if I draw the whole map into a canvas in the beginning, the game is much faster, compared to the solution, where I draw all the tiles separately. However now it is much more difficult to hide objects, that are behind map-features. (What I mean exactly becomes clear from the .love file).
To (partly) hide objects, I use stencils, which means that I only draw those parts, that are visible. Now the problem is, that each time I call love.graphics.setStencil(...), the whole stencil drawing function is called (which slows down my performance). In my case, the shape of the stencil is constant over the whole time. I would prefer to have the stencil drawn once and then use it without implicitly calling the stencil drawing function every frame.
I tried solving this by using canvases inside the stencil drawing function, however, even the transparent parts in the canvas block the view in the stencil. Same for using images with transparent parts in the stencil drawing function: I get rectangles then.
Any ideas how to switch stencils fast?
For demonstration, see attached .love-file.
Controls:
arrows: move player
a: jump
w,s: raise/lower current tile
e,d: change current tile type
i: spawn red ball
o: delete all balls
esc: quit
Please ignore slight bugs in player-physics. Also the hiding of the objects only works correctly for the flat landscape pieces.
I am currently working on an isometric game. As I am working on an older machine, I am concerned about performance. I figured that, if I draw the whole map into a canvas in the beginning, the game is much faster, compared to the solution, where I draw all the tiles separately. However now it is much more difficult to hide objects, that are behind map-features. (What I mean exactly becomes clear from the .love file).
To (partly) hide objects, I use stencils, which means that I only draw those parts, that are visible. Now the problem is, that each time I call love.graphics.setStencil(...), the whole stencil drawing function is called (which slows down my performance). In my case, the shape of the stencil is constant over the whole time. I would prefer to have the stencil drawn once and then use it without implicitly calling the stencil drawing function every frame.
I tried solving this by using canvases inside the stencil drawing function, however, even the transparent parts in the canvas block the view in the stencil. Same for using images with transparent parts in the stencil drawing function: I get rectangles then.
Any ideas how to switch stencils fast?
For demonstration, see attached .love-file.
Controls:
arrows: move player
a: jump
w,s: raise/lower current tile
e,d: change current tile type
i: spawn red ball
o: delete all balls
esc: quit
Please ignore slight bugs in player-physics. Also the hiding of the objects only works correctly for the flat landscape pieces.