Hi i'm working on my First 2D Game with XNA and I have a little problem. To give a running effect to my Sprite, I scroll through a SpriteSheet with this code(running right):
if (AnimationDelay == 6)
{
if (CurrentFrameR.X < SheetSizeR.X)
{
++CurrentFrameR.X;
}
else
{
CurrentFrameR.Y++;
CurrentFrameR.X = 1;
}
if (CurrentFrameR.Y >= SheetSizeR.Y)
{
CurrentFrameR.X = 0;
CurrentFrameR.Y = 0;
}
AnimationDelay = 0;
}
else
{
AnimationDelay += 1;
}
xPosition += xDeplacement;
And these are the objects used :
Point FrameSizeR = new Point(29, 33);
Point SheetSizeR = new Point(5, 1);
Point CurrentFrameR = new Point(0, 0);
int AnimationDelay = 0;
I have the same Code with different SpriteSheet when the sprite is running Left. Everything is working fine I'd say 90% of the time but the other 10% the sprite animation stays on one Frame of the SpriteSheet, on both directions(left and right) and it stays stuck until I close the program. The thing is I can't quite figure out why since it never happens at the same moment..Sometimes after 10,15,30 seconds and sometimes even on boot! Any idea why? Thanks in advance and let me know if you need any other parts of the code