Jump to content
  • Advertisement


Sign in to follow this  
  • entries
  • comments
  • views

Camera Movement

Sign in to follow this  


It used to be that you had to direct camera movement by the pixel level. For example moveCamera(180,70). So today I've been trying to get a scrollCamera method that would allow nice panning of the camera to work... with some (when I say some I mean little).

This is what would happen. I tell it to moveGoal(180,70,1000) which tells it to go to 180,70 in one second. In theory it works perfectly, but what happens is that the further the distance the more error there is. Scrolling only 400 pixels will produce a 0 to 50 pixel error. When I added a line that counted the number of ms in each updates it is different from what it should be.

It is getting very frustrating so I have decided to stop for tonight since I've been working on it for 3.5 hours :\ Maybe I'll figure it out by tomorrow morning.

The only thing that I can think of is that it is taking too long to render the screen, and causing problems with the update function, if this is the case there are going to be many more problems that arise from it. Luckly these problems won't occur on windows because you guys will actually get hardware acceleration...

Sign in to follow this  


Recommended Comments

How about moving the camera per frame based on how long the frame took to draw, so its consistant irregardless of framerate?

Let's say the frame took 20ms to draw. If the ideal framerate is 60 FPS, then each frame should take 1000/60=16.67ms each. So the camera would move by:

Camera.x += Camera.xVelocity * (timeTaken/(1000/60));
Camera.y += Camera.yVelocity * (timeTaken/(1000/60));


Unless you already know that, and I've misread what the underlying problem is. ;)

Share this comment

Link to comment
I thought that I was doing that, but then reading back over my code I realized that I'm using an update() that passes just the ideal frame-rate wait. In other words at 1000UPS it was sending 1ms waits regardless of long it took to draw.

Anyway, thanks! Its work'n now.

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!