Camera moving
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Camera moving
Hi! I'm trying to do a platform game where the camera only should move when the character gets outside of the current screen. Then the camera should move one screen width/height in the character's moving direction. I've almost got it to work, but as you can see, it's not working exactly as I want it to. I hope someone knows how to do it.
- Attachments
-
- game.love
- (266.1 KiB) Downloaded 303 times
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Camera moving
Well, you could start by describing the problem, I don't see anything that's clearly wrong (though there is a flicker when switching to the next screen)
Re: Camera moving
Well, the problem is that when the character goes to the left more than one screen and then goes back again, the camera doesn't follow. I don't know if my way of doing this screen movement is the best so I'm wondering if someone any better idea that actually works without any x and y valuses hard coded, as it is right now. And the flicker is also a problem. I assume that it has something to do with the way I have done the coding..
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Camera moving
Hmm, right it seems to be the hardcoding, can't you use some function of camera to get the correct height and width? love.graphics.getHeight()/getWidth()? And, you might want to do something like:
(this is with a 2-'unit' area in which you can move to the next screen)
Code: Select all
if x % width <= 2 then
--move right
elseif x % width >= width-2 then
--move left
end
Re: Camera moving
Ok, so what is this code really doing? Can't figure out what the percent sign is doing. In my current code i move the camera with getCamera():setOrigin(x, y). So what is supposed to be the x that the camera is moving to?
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Camera moving
% means modulus: the rest after an integer division: 17 / 4 = 4 modulus 1, so 17 % 4 = 1.eliasaif wrote:Ok, so what is this code really doing? Can't figure out what the percent sign is doing. In my current code i move the camera with getCamera():setOrigin(x, y). So what is supposed to be the x that the camera is moving to?
The x in bartbes's code is (I think) the player position.
This method is still somewhat inflexible. I would suggest looking at Jump Game for a more flexible solution.
Help us help you: attach a .love.
Re: Camera moving
Hi again! I still can't find out how to do this.. I've tried something like this code:
The problem is that I can't figure out what I should set the camera origin to. In this code, it sais x and y, but I don't know what the x and y should be. Does anyone have any idea how I can get this working?
Code: Select all
if playerx % width <= 2 then
getCamera():setOrigin(x, y)
elseif playerx % width >= width-2 then
getCamera():setOrigin(x, y)
end
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Camera moving
Probably the playerx.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Camera moving
I would say something like x = current_x + width / 2 or x = current_x + width. It depends on whether you still want to see a bit of the old position.
The y stays the same, I think.
The y stays the same, I think.
Help us help you: attach a .love.
Re: Camera moving
It's like it's looping the moving process by it self. Something must still be wrong in the code. I've attached the game below.
- Attachments
-
- game.love
- (442.01 KiB) Downloaded 277 times
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests