Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411595 Posts in 69386 Topics- by 58444 Members - Latest Member: FightingFoxGame

May 07, 2024, 03:57:40 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)2D scrolling background.
Pages: [1]
Print
Author Topic: 2D scrolling background.  (Read 997 times)
Nugsy
Level 10
*****



View Profile
« on: August 17, 2010, 07:09:44 AM »

Hey guys, i'm super stuck with a little racing game i'm currently working on. It's the view that is stumping me atm, i've looked at numerous tutorials but nothing seems to fit.

Basically, it's a top down racing game, but it has a fixed viewpoint. So instead of turning your car, you turn the entire world (like in 3D). I need the car to be at a fixed position on the window (the window is 320x600, the car is at 160,480) and have the world rotate around that position. But the camera needs to be above this point, not centered on the car.
I can't manage to apply velocity without the car going off of the screen, and if i lock the car into position on the screen it doesn't stick to it's position in the world.

That description is probably pretty hard to understand, so here's a screenshot to show you what i mean. Please ignore the horrible placeholder background haha.



The thing is, i know the answer is probably something ridiculously simple. But i'm overthinking it.

Any help you can offer is appreciated! SmileyHand Thumbs Up Right
Logged


Theotherguy
Level 1
*



View Profile
« Reply #1 on: August 17, 2010, 07:21:02 AM »

What you need to do is separate your camera coordinates from your world coordinates, and then apply a transform before drawing anything.

In other words, you need a world reference frame that everything is relative to, then transform it to the camera frame, and then transform it to the screen:

World Frame (in game units) -> Camera Frame (in game units) -> Screen (in pixels).

You can do this by applying a matrix transform to all of your world coordinates that reflects your camera's position and rotation.

Then, you can simply move your camera around the world at will, and things will be drawn in the correct place for you.

Check out my Vector Arithmetic tutorial for ideas on how to do this:

http://forums.tigsource.com/index.php?topic=14154.0
Logged

Nugsy
Level 10
*****



View Profile
« Reply #2 on: August 17, 2010, 07:56:15 AM »

Awesome! I've just had a skim read of it and it looks really helpful.
I'll have a better look at it later and give it a go. Thankyou! Smiley
Logged


Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic