Game Development Reference
In-Depth Information
if x < 0 or x > _W then dirX = − dirX end
if y < 0 or y > _H then dirY = − dirY end
end
end
So, whenever we move away from the window, the love.focus function is triggered, and that sets
the current variable to true or false depending on if the window has focus. In the update, we
increment the position of our image if the current variable is not false or nil . So, the moment we
switch away from the application window, the image freezes, and when we click the window again, it
starts to move.
love.update function,
love.keypressed function.
theImage = love.graphics.newImage("myImage3.png")
x = 50
y = 50
love.graphics.setColor(0,0,0,255)
love.graphics.setBackgroundColor(255,255,255,255)
end
function love.draw()
love.graphics.draw(theImage, x, y)
end
function love.keypressed(key, unicode)
if key=="up" then
y = y - dirY
elseif key =="down" then
y = y + dirY
elseif key=="left" then
x = x - dirX
elseif key =="right" then
x = x + dirX
end
end
In this example, the image only moves when the relevant keys are pressed.
 
Search WWH ::




Custom Search