Scrolling 2D Background XNA Tutorial Question
Please see below:
A small FYI and a question from myself as I start to go through this peice by peice.
(code is placed inside of [code] blocks just for easier reading, and incase the forum contains the ability to make it look nice.)
I followed the tutorial and ran the created code with an image that was 800x600 and noticed that the peice was about 1 inch to far from the left. There appears to be a small typo in the tutorial:
[code]
// Set the origin to the center of the texture.
origin = new Vector2( mytextureinfo.Height / 2, mytextureinfo.Width / 2 );
// Set the screen position to the center of the screen.
screenpos = new Vector2( screenwidth / 2, screenheight / 2 );
[/code]
Should really read:
[code]
// Set the origin to the center of the texture.
origin = new Vector2( mytextureinfo.Height / 2, mytextureinfo.Width / 2);
// Set the screen position to the center of the screen.
screenpos = new Vector2(screenheight / 2, screenwidth / 2);
[/code]
I noticed that they changed the order of the math which throws things all out of whack. I think this might need to be fixed in the tutorials for the next release.
My question is this:
After correcting the code for the image, it scrolls down by 100 pixels and then when the image hits the following snipit block:
[code]
// If the entire screen isn't covered, draw a second
// texture above the first by offsetting the screen position
if (screenpos.Y > mytextureinfo.Height/2)
{
Batch.Draw( mytexture, screenpos - offset, null, Color.White, 0, origin, 1, SpriteEffects.None, 0f );
}
[/code]
The image repeats, but it makes the first image disappear... so basically it leaves a blank spot and you can visibly see the background repeat, and that looks kind of ugly.
Any ideas on this one?
Thank you in advance,
-TmK

