I guess that the problem is that the condition is still true.
And:
WHAT HAVE YOU DONE?! Why fullscreen?! It crashed on me, leaving me with this crappy resolution!
Camera moving
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Camera moving
Oh! I've done it again! I'm sorry for that. I'm just used to run thing the way they are ment to be.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Camera moving
What fun:
Two mistakes:
Calculating playerviewx is left as an exercise to the reader.
Code: Select all
if playerx % width >= 2 then
x = originx + width
getCamera():setOrigin(x, y)
elseif playerx % width <= width-2 then
x = originx - width
getCamera():setOrigin(x, y)
else
x = 0
getCamera():setOrigin(x, y)
end
- The if and elseif should switch comparison.
- You compare playerx, while you should compare playerviewx (i.e.: "playerx - viewx").
Code: Select all
if playerviewx % width <= 2 then
x = originx + width
getCamera():setOrigin(x, y)
elseif playerviewx % width >= width-2 then
x = originx - width
getCamera():setOrigin(x, y)
else
x = 0
getCamera():setOrigin(x, y)
end
Last edited by Robin on Sat Jun 06, 2009 12:06 pm, edited 1 time in total.
Help us help you: attach a .love.
Re: Camera moving
Isn't originx what you call playerviewx? It's the current origin of the camera.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Camera moving
Oh, I didn't see originx. But no, it's a tad different. I think:eliasaif wrote:Isn't originx what you call playerviewx? It's the current origin of the camera.
Code: Select all
playerviewx = playerx - originx
Help us help you: attach a .love.
Re: Camera moving
I tried to do like this:
But it's still doing this loop that gets the camera to fly away all the time.. I know it's because playerviewx % width <= 1280/50 or playerviewx % width >= width-1280/50 is still true. I still can't figure this out.
Code: Select all
playerx = playerbody:getX()
playery = playerbody:getY()
originx, originy = getCamera():getOrigin()
width = love.graphics.getWidth()
height = love.graphics.getHeight()
playerviewx = playerx - originx
if playerviewx % width <= 1280/50 then
x = originx + width
getCamera():setOrigin(x, y)
elseif playerviewx % width >= width-1280/50 then
x = originx - width
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
Well, the case here is that you move your origin to the next screen, where it will be within the 'back' zone, so it will go back, where it will be in the 'forward' zone....
So... maybe move half a screen, or just find a better solution .
So... maybe move half a screen, or just find a better solution .
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Camera moving
Another approach would be like I did in Jump Game. Instead of changing the view, I set viewdx = 20 (or something like that), and in update, I put the following code:
(replace setview() with your camera moving code)
Code: Select all
if viewdx > .1 then
setview(+dt)
viewdx = viewdx - dt
elseif viewdx < -.1 then
setview(-dt)
viewdx = viewdx + dt
end
Help us help you: attach a .love.
Re: Camera moving
Thanks for all good ideas! Now I have solved my problem. It's not really anything like the above, but it works fine. Here's my code if someone's interested.
Code: Select all
playerx = playerbody:getX()
playery = playerbody:getY()
originx, originy = getCamera():getOrigin()
width = love.graphics.getWidth()
height = love.graphics.getHeight()
if playerx > originx+(width/2) then
x = x + width
getCamera():setOrigin(x, y)
elseif playerx < originx-(width/2) then
x = x - width
getCamera():setOrigin(x, y)
end
if playery > originy+height then
y = y + height
getCamera():setOrigin(x, y)
elseif playery < originy-height then
elseif playery < originy then
y = y - height
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
Let me try and describe it with one word:
better
Well, that went well... maybe I can start typing sentences next...
better
Well, that went well... maybe I can start typing sentences next...
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 8 guests