Page 2 of 2

Re: Camera moving

Posted: Thu Jun 04, 2009 6:53 pm
by bartbes
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!

Re: Camera moving

Posted: Thu Jun 04, 2009 6:59 pm
by eliasaif
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.

Re: Camera moving

Posted: Fri Jun 05, 2009 10:30 am
by Robin
What fun:

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
Two mistakes:
  1. The if and elseif should switch comparison.
  2. You compare playerx, while you should compare playerviewx (i.e.: "playerx - viewx").
Change it:

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
Calculating playerviewx is left as an exercise to the reader.

Re: Camera moving

Posted: Fri Jun 05, 2009 11:14 am
by eliasaif
Isn't originx what you call playerviewx? It's the current origin of the camera.

Re: Camera moving

Posted: Fri Jun 05, 2009 11:32 am
by Robin
eliasaif wrote:Isn't originx what you call playerviewx? It's the current origin of the camera.
Oh, I didn't see originx. But no, it's a tad different. I think:

Code: Select all

playerviewx = playerx - originx
It's where the playerx is on the screen.

Re: Camera moving

Posted: Sat Jun 06, 2009 9:32 am
by eliasaif
I tried to do like this:

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
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. :P

Re: Camera moving

Posted: Sat Jun 06, 2009 9:36 am
by bartbes
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 :P.

Re: Camera moving

Posted: Sat Jun 06, 2009 12:06 pm
by Robin
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:

Code: Select all

if viewdx > .1 then
    setview(+dt)
    viewdx = viewdx - dt
elseif viewdx < -.1 then
    setview(-dt)
    viewdx = viewdx + dt
end
(replace setview() with your camera moving code)

Re: Camera moving

Posted: Sat Jun 06, 2009 3:26 pm
by eliasaif
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

Re: Camera moving

Posted: Sun Jun 07, 2009 5:51 am
by bartbes
Let me try and describe it with one word:
better

Well, that went well... maybe I can start typing sentences next...