Jump to content
Site Stability Read more... ×
  • Advertisement
Sign in to follow this  

XNA Platformer Scrolling Resolution Problem

This topic is 2878 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 I've been trying for some time now to get resolution independency into the XNA platformer kit with sidescrolling but I can't get it to work right.
What I'm doing is using a transform matrix to scale everything up, which works just fine but the problem is the scrolling mechanics don't work how they're supposed to when I change the resolution to anything other than 800x480 (default).

The problem must be somewhere in this function but I just can't figure it out :(
private void ScrollCamera(Viewport viewport)
const float ViewMargin = 0.35f;

// Calculate the edges of the screen
float marginWidth = (viewport.Width) * ViewMargin;
float marginLeft = (cameraPosition * 1.0f) + marginWidth;
float marginRight = (cameraPosition * 1.0f) + (viewport.Width) - marginWidth;

// Calculate how far to scroll when the player is near the edges of the screen
float cameraMovement = 0.0f;

if (Player.Position.X < marginLeft)
cameraMovement = (Player.Position.X - marginLeft);

else if (Player.Position.X > marginRight)
cameraMovement = ((Player.Position.X) - marginRight);


// Update the camera position, but prevent scrolling off the ends of the level
float maxCameraPosition = Tile.Width * Width - (viewport.Width);
cameraPosition = MathHelper.Clamp(cameraPosition + cameraMovement, 0.0f, maxCameraPosition);


Any help would be appreciated :/

BTW I'm talking about this sidescrolling : http://msdn.microsoft.com/en-us/library/dd254919(v=XNAGameStudio.31).aspx

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.

GameDev.net 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!