camera?
Posted: Thu Mar 19, 2009 8:53 am
How can i make a camera to follow a 'sprite'?
Code: Select all
love.filesystem.require("camera.lua")
function load()
player = love.graphics.newImage("player.png")
background = love.graphics.newImage("background.png")
playerX = 50
playerY = 50
getCamera():setScreenOrigin(0.5, 0.5) -- Set this to the middle of the screen.
end
function update(dt)
if love.keyboard.isDown(love.key_left) then
playerX = playerX - 1
end
if love.keyboard.isDown(love.key_right) then
playerX = playerX + 1
end
if love.keyboard.isDown(love.key_up) then
playerY = playerY - 1
end
if love.keyboard.isDown(love.key_down) then
playerY = playerY + 1
end
getCamera():setOrigin(playerX, playerY) -- Focus on the player, nothing else. This will follow the player around.
end
function draw()
love.graphics.draw(background, 0, 0)
love.graphics.draw(player, playerX, playerY)
end
I'm glad. Play around with it and read Camera's documentation (on the Wiki, mostly, I think) and get a good sense of what's possible. I think you'll find it's more fun to play around and figure things out for yourself. I know I certainly enjoy it immensely.someguy99 wrote:OK,it worked