我正在使用 XNA 开发我的第一个 2D 游戏,但我遇到了一个小问题。为了给我的 Sprite 提供运行效果,我使用以下代码滚动SpriteSheet(向右运行):
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;
}
这些是使用的对象:
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