Jump to content
  • Advertisement
Sign in to follow this  
Funkymunky

manually scrolling by "depth" in 2d

This topic is 3810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im working on a sidescroller, orthogonal projection so no real depth. I want to place an object in the "background" and have it scroll from left to right slower than an object in the "foreground." Parallax scrolling. How can I manually calculate the position of an object in 2D based on a "depth" value that I determine? How do I figure out where to draw it so that it will scroll slower because its in the "background"?

Share this post


Link to post
Share on other sites
Advertisement
I wouldn't actually modify the position of the objects, because then you get into the problem of not knowing what the real position of something is versus its "fake" position you use to simulate parallax. And it doesn't really make sense to do so either, since objects don't have to physically move in order for them to appear to be moving at different speeds (i.e. when the camera is on motion).

Instead I would throw your objects into a pipeline of sorts that calculates view-space position based on world-space position. Since your project is a 2D side-scroller this should be rather simple. Usually there's a straightforward duality between camera translation and object translation, such that if your camera translates X units in one direction, it appears as though your objects translated X units in the opposite direction. With parallax, a camera translation of X units in one direction would correspond to an apparent object translation of X/(D+C) units in the other direction, where D is depth of the object and C is an arbitrary constant used to control the "initial condition", or how fast objects move at depth 0. So hopefully that clears some things up for you :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!