Advertisement Jump to content
Sign in to follow this  

ScrollBar help

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

Hello all.
Currently I'm working on a 2d level editor with xna and winforms and i cant seem to get a formula for a scrollbar to work. At the moment I'm only doing it for 1 axis.

Here are the variables I have:
MapWidth = 100
Scrollbar.Width = 556

And i need to find some way so by the time you reach the end of the scroll bar your at the end of the map.

Here's what i have currently:

void hsbView_Scroll(object sender, ScrollEventArgs e)
camera.Position = new Vector2(hsbView.Value, 0);

if ((camera.Position.X + mapDisplay.Width) / 32 < levels[0].MapWidth)
camera.Position = new Vector2(camera.Position.X - 32, 0);

Thanks for reading.

Share this post

Link to post
Share on other sites
Out of my head this should do the trick, however you can only safely call it if the level is actually bigger than the display:

camera.Position.X = ( levels[0].MapWidth * 32 - mapDisplay.Width ) * hsbView.Value / ( hsbView.Maximum - hsbView.Minimum )

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!