XNA Platformer Scrolling Resolution Problem

Started by
-1 comments, last by lipsryme 12 years, 4 months ago
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

This topic is closed to new replies.

Advertisement