Skip to content

Instantly share code, notes, and snippets.

@wilbefast
Created May 20, 2014 20:34
Show Gist options
  • Save wilbefast/cd78bfac14cbf1b9e508 to your computer and use it in GitHub Desktop.
Save wilbefast/cd78bfac14cbf1b9e508 to your computer and use it in GitHub Desktop.
Push and pop canvas object in Löve 2D.
useful.canvasStack = {}
function useful.pushCanvas(newCanvas)
table.insert(useful.canvasStack, love.graphics.getCanvas())
love.graphics.push()
love.graphics.origin()
love.graphics.setCanvas(newCanvas)
end
function useful.popCanvas()
local n = #useful.canvasStack
if n > 0 then
local oldCanvas = useful.canvasStack[n]
table.remove(useful.canvasStack, n)
love.graphics.pop()
love.graphics.setCanvas(oldCanvas)
else
love.graphics.pop()
love.graphics.setCanvas()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment