Bruce
Bruce

Reputation: 235

Calculating parallax layer world coordinates?

I'm trying to position a sprite in a 2d game at a certain world position on a parallax layer.

So if my parallax layer has a scroll factor of 0.5, when the camera moves 2 pixels, that layer moves 1 pixel. I'm trying to align trees along the bottom of the maximum extents of the world.

So how do I calculate the position of the sprite I want to place on the parallax layer so that it shows up where I want in the world? My camera's origin is in the top left if that makes a difference.

I've tried a lot of formulas but no luck and Google isn't being helpful.

Any help please?

Thanks!

Upvotes: 1

Views: 1314

Answers (1)

Bruce
Bruce

Reputation: 235

Got it! Finally!

For any future searchers:

 screen position x = (world position x * scroll factor) +
     (camera width * (1 - scroll factor))

 screen position y = (world position y * scroll factor) +
     (camera height * (1 - scroll factor))

Good luck!

Upvotes: 4

Related Questions