Witam mam problem taki iż podczas przemieszczania się tła jest tak
5
4
3
2
1
od 1 leci w dół aż do 5, ale po 5 ma być od nowa ten sam ciąg... Ale coś mi się nie udaje i w ogóle nie chce działać... Poniżej zamieszczam kod, może ktoś będzie wiedział w czym tkwi problem.
Jest to XNA.
namespace GRA
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Sprite mSprite;
Sprite mBackgroundOne;
Sprite mBackgroundTwo;
Sprite mBackgroundThree;
Sprite mBackgroundFour;
Sprite mBackgroundFive;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
mSprite = new Sprite();
mBackgroundOne = new Sprite();
mBackgroundOne.Scale = 1.0f;
mBackgroundTwo = new Sprite();
mBackgroundTwo.Scale = 1.0f;
mBackgroundThree = new Sprite();
mBackgroundThree.Scale = 1.0f;
mBackgroundFour = new Sprite();
mBackgroundFour.Scale = 1.0f;
mBackgroundFive = new Sprite();
mBackgroundFive.Scale = 1.0f;
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
mSprite.LoadContent(this.Content, "statek");
mSprite.Position = new Vector2(125, 245);
mBackgroundOne.LoadContent(this.Content, "tlo1");
mBackgroundOne.Position = new Vector2(0, 0);
mBackgroundTwo.LoadContent(this.Content, "tlo2");
mBackgroundTwo.Position = new Vector2(0, mBackgroundOne.Position.Y - mBackgroundOne.Size.Height);
mBackgroundThree.LoadContent(this.Content, "tlo3");
mBackgroundThree.Position = new Vector2(0, mBackgroundTwo.Position.Y - mBackgroundTwo.Size.Height);
mBackgroundFour.LoadContent(this.Content, "tlo4");
mBackgroundFour.Position = new Vector2(0, mBackgroundThree.Position.Y - mBackgroundThree.Size.Height);
mBackgroundFive.LoadContent(this.Content, "tlo5");
mBackgroundFive.Position = new Vector2(0, mBackgroundFour.Position.Y - mBackgroundFour.Size.Height);
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
if (mBackgroundOne.Position.Y < -mBackgroundOne.Size.Height)
{
mBackgroundOne.Position.Y = mBackgroundFive.Position.Y - mBackgroundFive.Size.Height;
}
if (mBackgroundTwo.Position.Y < -mBackgroundTwo.Size.Height)
{
mBackgroundTwo.Position.Y = mBackgroundOne.Position.Y - mBackgroundOne.Size.Height;
}
if (mBackgroundThree.Position.Y < -mBackgroundThree.Size.Height)
{
mBackgroundThree.Position.Y = mBackgroundTwo.Position.Y - mBackgroundTwo.Size.Height;
}
if (mBackgroundFour.Position.Y < -mBackgroundFour.Size.Height)
{
mBackgroundFour.Position.Y = mBackgroundThree.Position.Y - mBackgroundThree.Size.Height;
}
if (mBackgroundFive.Position.Y < -mBackgroundFive.Size.Height)
{
mBackgroundFive.Position.Y = mBackgroundFour.Position.Y - mBackgroundFour.Size.Height;
}
Vector2 aDirection = new Vector2(0, 1);
Vector2 aSpeed = new Vector2(0, 60);
mBackgroundOne.Position += aDirection * aSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
mBackgroundTwo.Position += aDirection * aSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
mBackgroundThree.Position += aDirection * aSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
mBackgroundFour.Position += aDirection * aSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
mBackgroundFive.Position += aDirection * aSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
spriteBatch.Begin();
mBackgroundOne.Draw(this.spriteBatch);
mBackgroundTwo.Draw(this.spriteBatch);
mBackgroundThree.Draw(this.spriteBatch);
mBackgroundFour.Draw(this.spriteBatch);
mBackgroundFive.Draw(this.spriteBatch);
mSprite.Draw(this.spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
}
}
}