Camera movement to follow player problems
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 15
- Joined: Wed Jun 26, 2013 5:41 pm
Camera movement to follow player problems
hey guys! first off id like to say IM NEW! so im sorry if i break some rules or piss some people off, i promise im not trying to :p im just trying to get this problem solved! alright moving on to the problem, i want the camera to start following my player once he reaches half way through the screen, now it does that when the player moves right, but it does not when he moves up, left, or down, like i said im new, ive been using this stuff for like a few hours max, so maybe someone could help me understand? im sure its a stupid mistake.
- Attachments
-
- camera.lua
- (822 Bytes) Downloaded 283 times
-
- main.lua
- (1.22 KiB) Downloaded 384 times
-
- Windwaker.love
- (992.49 KiB) Downloaded 196 times
Re: Camera movement to follow player problems
okay first off your map picture is too big not all computers can run such big maps i would make a props.lua/house.lua and use tables
secound, the camera problem:
main.lua
secound, the camera problem:
main.lua
Code: Select all
if player.y > love.graphics.getWidth() / 2 then
camera.y = player.y - love.graphics.getHeight() / 2
end
-
- Prole
- Posts: 15
- Joined: Wed Jun 26, 2013 5:41 pm
Re: Camera movement to follow player problems
alright man, i did that, but now the problem is that when the game first starts, the player walks all the way to the bottom of the screen, it glitches, and then it does it properly, any ideas? this happens every time
Re: Camera movement to follow player problems
I'd implement a camera like this: By default, make the camera center around the player. Then check if the camera is within the bounds of the map and if not, correct it. So here you go (this by the way has to be inside the 'if gamestate == "player"'-part not in the general love.update. The menu does not have camera movement)
In love.load I added these lines:
Later, when you work more on your project you should then implement a function that reads the height and width of the map, instead of hard coding it, like I have done it now.
And you should really make the window smaller.
Code: Select all
camera.x = player.x - love.graphics.getWidth()/2
camera.y = player.y - love.graphics.getHeight()/2
if camera.x < 0 then camera.x = 0 end
if camera.y < 0 then camera.y = 0 end
if camera.x > mapWidth - love.graphics.getWidth() then
camera.x = mapWidth - love.graphics.getWidth()
end
if camera.y > mapHeight - love.graphics.getHeight() then
camera.y = mapHeight - love.graphics.getHeight()
end
Code: Select all
mapHeight = 1988
mapWidth = 2720
And you should really make the window smaller.
Check out my blog on gamedev
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Camera movement to follow player problems
In case this helps, you might want to try gamera (disclaimer: I'm gamera's author)
When I write def I mean function.
-
- Prole
- Posts: 15
- Joined: Wed Jun 26, 2013 5:41 pm
Re: Camera movement to follow player problems
thanks guys! problem solved!
Who is online
Users browsing this forum: Ahrefs [Bot] and 4 guests