camera?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
someguy99
Prole
Posts: 16
Joined: Tue Mar 17, 2009 5:34 pm

camera?

Post by someguy99 »

How can i make a camera to follow a 'sprite'?
User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: camera?

Post by qubodup »

What do you have so far?
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
User avatar
someguy99
Prole
Posts: 16
Joined: Tue Mar 17, 2009 5:34 pm

Re: camera?

Post by someguy99 »

What do you mean what i have?2 images,one moves.Nothing special.
User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: camera?

Post by qubodup »

Currently, you use the input to move the player sprite.

Use the imput to move every image BUT the player sprite instead.
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
User avatar
someguy99
Prole
Posts: 16
Joined: Tue Mar 17, 2009 5:34 pm

Re: camera?

Post by someguy99 »

"Use the input to move every image BUT the player sprite instead"
What does that mean?
User avatar
Xcmd
Party member
Posts: 211
Joined: Fri Feb 13, 2009 10:45 pm

Re: camera?

Post 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.
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
User avatar
someguy99
Prole
Posts: 16
Joined: Tue Mar 17, 2009 5:34 pm

Re: camera?

Post by someguy99 »

Hey,thanks.Looks easy as pie.Only were can i find the "camera.lua" header file?
User avatar
Xcmd
Party member
Posts: 211
Joined: Fri Feb 13, 2009 10:45 pm

Re: camera?

Post by Xcmd »

Hmm, yes, right. Here you are: http://love2d.org/forum/viewtopic.php?f=5&t=419 -- By our own osuf oboys.
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
User avatar
someguy99
Prole
Posts: 16
Joined: Tue Mar 17, 2009 5:34 pm

Re: camera?

Post by someguy99 »

OK,it worked :)
User avatar
Xcmd
Party member
Posts: 211
Joined: Fri Feb 13, 2009 10:45 pm

Re: camera?

Post 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.
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest