Camera movement
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 16
- Joined: Fri Jan 15, 2016 6:33 pm
Camera movement
Hello, how do I make the camera follow my player? In my game you can move the airplane with the arrow keys, but I want the camera to follow it. Any help? Thanks
Re: Camera movement
Do you use a camera library? Which one? Usually, you have to update the camera position together with the player position.
hump.camera, has some utilities that make these things easier, e.g.:
If you do not use a camera library, you can center the "camera" on the player with [wiki]love.graphics.translate[/url]:
hump.camera, has some utilities that make these things easier, e.g.:
Code: Select all
function love.update(dt)
player:update(dt) -- moves player
cam:lockPosition(player.x, player.y) -- locks the camera on the player
end
Code: Select all
function love.draw()
love.graphics.push()
love.graphics.translate(-player.x, -player.y)
draw_world()
love.graphics.pop()
draw_hud()
end
-
- Prole
- Posts: 16
- Joined: Fri Jan 15, 2016 6:33 pm
Re: Camera movement
Ok thanks. So his is my character:
plane = love.graphics.draw("plane.png")
How would I center the camera to the plane?
plane = love.graphics.draw("plane.png")
How would I center the camera to the plane?
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Camera movement
by having or similar.
lg.draw can't draw anything from a string parameter (according to the wiki which you should really read through), so what you posted most certainly does not work.
Code: Select all
-- outside any function:
local plane = {}
-- in love.load:
plane.x = 0
plane.y = 0
plane.graphics = love.graphics.newImage("plane.png")
-- in love.update, you modify the x and y members of plane with keypresses or something
-- in love.draw:
love.graphics.draw(plane.graphics, plane.x, plane.y)
-- Note that this won't move the camera, you'll need to add in one of the above codes from vrld.
lg.draw can't draw anything from a string parameter (according to the wiki which you should really read through), so what you posted most certainly does not work.
Last edited by zorg on Sun Jan 17, 2016 4:20 pm, edited 1 time in total.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
-
- Prole
- Posts: 16
- Joined: Fri Jan 15, 2016 6:33 pm
Re: Camera movement
Thanks zorg! You are always helping me
Who is online
Users browsing this forum: Bing [Bot] and 4 guests