Jump to content
  • Advertisement
Sign in to follow this  
EvilNando

2D camera zoomin outside the level

This topic is 3001 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

hi guys is there a way to clamp my 2d camera so that I can only zoom out to where the entire level can be seen on the whole screen (wide-wise)

heres the problem that Im getting



[SOURCE]
/// <summary>
/// Check if camera position is beyond current limits
/// </summary>
public void ClampToArea()
{
if (location.X >= game_size.Width - viewport.Width / 2 + (viewport.Width / 2 - ((viewport.Width / 2) / zoom)))
{
location.X = game_size.Width - viewport.Width / 2 + (viewport.Width / 2 - ((viewport.Width / 2) / zoom));
}

if (location.Y >= game_size.Height - viewport.Height / 2 + (viewport.Height / 2 - ((viewport.Height / 2) / zoom)))
{
location.Y = game_size.Height - viewport.Height / 2 + (viewport.Height / 2 - ((viewport.Height / 2) / zoom));
}

if (location.X < viewport.Width / 2)
{
location.X = viewport.Width / 2;
}

if (location.Y < viewport.Height / 2)
{
location.Y = viewport.Height / 2;
}
}
[/SOURCE]

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!