|
-
December 6th, 2011, 02:17 PM
#1
Problems making a sprite move in C#
Hello, I am writing code to make an animation move on the screen, but when I run my code it doesn't move. I do not get any errors but does not work the way I want it to. Can someone please look at my code and let me know if there is something I am missing? I am running framework 4.0
Code:
void UpdateSprite(GameTime gameTime)
{
// Move the sprite by speed, scaled by elapsed time.
spritePosition +=
spriteSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
int MaxX =
graphics.GraphicsDevice.Viewport.Width - myTexture.Width;
int MinX = 0;
int MaxY =
graphics.GraphicsDevice.Viewport.Height - myTexture.Height;
int MinY = 0;
// will check for bounce.
if (spritePosition.X > MaxX)
{
spriteSpeed.X *= -1;
spritePosition.X = MaxX;
}
else if (spritePosition.X < MinX)
{
spriteSpeed.X *= -1;
spritePosition.X = MinX;
}
if (spritePosition.Y > MaxY)
{
spriteSpeed.Y *= -1;
spritePosition.Y = MaxY;
}
else if (spritePosition.Y < MinY)
{
spriteSpeed.Y *= -1;
spritePosition.Y = MinY;
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|