Skip to content

Instantly share code, notes, and snippets.

@EngineerSmith
Created April 25, 2020 10:35
Show Gist options
  • Save EngineerSmith/d11ff3bd0056d19414ce7df575d22ed9 to your computer and use it in GitHub Desktop.
Save EngineerSmith/d11ff3bd0056d19414ce7df575d22ed9 to your computer and use it in GitHub Desktop.
local lg = love.graphics
local canvas = lg.newCanvas(128,128) -- treat canvas as your sprite, but I was too lazy to draw a debug image, so I made one from a canvas
lg.setCanvas(canvas) -- French flag debug graphic
lg.clear(1,1,1)
lg.setColor(0.2,0.2,0.8)
lg.rectangle("fill", 0, 0, 43,128)
lg.setColor(0.8,0.2,0.2)
lg.rectangle("fill",88,0, 43,128)
lg.setColor(1,1,1)
lg.setCanvas()
local time = 0
local dir = 1
function love.update(dt)
time = time + dt * dir
if dir == 1 and time > 1 then
dir = -1
time = 1
elseif dir == -1 and time < -1 then
dir = 1
time = -1
end
end
local halfwidth = canvas:getWidth()/2
function love.draw()
lg.push()
lg.translate(200+halfwidth,200)
lg.scale(time, 1) -- ensure there's a 1 or it'll scale on both axis
lg.translate( -halfwidth, 0)
lg.draw(canvas)
lg.pop()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment