Page 1 of 1

camera?

Posted: Thu Mar 19, 2009 8:53 am
by someguy99
How can i make a camera to follow a 'sprite'?

Re: camera?

Posted: Thu Mar 19, 2009 9:05 am
by qubodup
What do you have so far?

Re: camera?

Posted: Thu Mar 19, 2009 9:51 am
by someguy99
What do you mean what i have?2 images,one moves.Nothing special.

Re: camera?

Posted: Thu Mar 19, 2009 1:37 pm
by qubodup
Currently, you use the input to move the player sprite.

Use the imput to move every image BUT the player sprite instead.

Re: camera?

Posted: Thu Mar 19, 2009 7:45 pm
by someguy99
"Use the input to move every image BUT the player sprite instead"
What does that mean?

Re: camera?

Posted: Thu Mar 19, 2009 9:11 pm
by Xcmd

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
Lemme know if you need further explanation.

Re: camera?

Posted: Fri Mar 20, 2009 5:40 am
by someguy99
Hey,thanks.Looks easy as pie.Only were can i find the "camera.lua" header file?

Re: camera?

Posted: Fri Mar 20, 2009 7:02 am
by Xcmd
Hmm, yes, right. Here you are: http://love2d.org/forum/viewtopic.php?f=5&t=419 -- By our own osuf oboys.

Re: camera?

Posted: Fri Mar 20, 2009 9:57 am
by someguy99
OK,it worked :)

Re: camera?

Posted: Fri Mar 20, 2009 4:20 pm
by Xcmd
someguy99 wrote:OK,it worked :)
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.

But I still ask for help when I get well and truly stumped.