TehOne

I was following the example/tutorial on this page http://msdn2.microsoft.com/en-us/library/bb203866.aspx and I think it may have a problem. It seems to skip the last frame of the image.

Here is my example image, it is 256x64 with 4 64x64 frames as specified in the example.

http://tehone.com/images/xna/ball-4frames.png

If you plug in the code on that page with this image, it skips the last frame of my image. Is there a mistake with the example Or am I missing something

Thanks.


Re: XNA Framework Problem with MSDN 2D animate sprite example?

TehOne

Btw... If i change the code and get rid of the -1 in the new Frame calculation, then the animation works fine.

Can anyone tell me why they would be -1 from the framecount in the first place

Thanks again.

From this:

// class AnimatedTexture
public void UpdateFrame( float elapsed )
{
if (Paused)
return;
TotalElapsed += elapsed;
if (TotalElapsed > TimePerFrame)
{
Frame++;
// Keep the Frame between 0 and the total frames, minus one
Frame = Frame % (framecount - 1);
TotalElapsed -= TimePerFrame;
}
}


To this:
// class AnimatedTexture
public void UpdateFrame( float elapsed )
{
if (Paused)
return;
TotalElapsed += elapsed;
if (TotalElapsed > TimePerFrame)
{
Frame++;
// Keep the Frame between 0 and the total frames, minus one
Frame = Frame % framecount;
TotalElapsed -= TimePerFrame;
}
}





Re: XNA Framework Problem with MSDN 2D animate sprite example?

dczraptor

it just depends on whether you set framecount = 0 or framecount = 1 at the beginning of your program. If you set it to framecount = 1, then you will need Frame = Frame % (framecount -1) to get a correct number, while if you do framecount = 0, then you will not need to subtract one.




Re: XNA Framework Problem with MSDN 2D animate sprite example?

TehOne

If you look at the example on MSDN, you will see that framecount is actually a parameter to the Load method of the AnimatedTexture class. And, you (according to what I can tell from the example) are supposed to set this to the total amount of frames in your image. My image (and the example given in the code) has 4 frames. But that example, out of the box, skips the 4th frame of the image. That was where my confusion comes from (or my thinking that the example is wrong).

Thanks.




Re: XNA Framework Problem with MSDN 2D animate sprite example?

NinjaCoder

Ooh, my first post. :-)

I believe TehOne is right - in the example MSDN gives you line 50 has something like:

Frame = Frame % (framecount) - 1;

Where it should be:

Frame = Frame % (framecount);

This is cause FrameCount % FrameCount equals zero, so you'll loop back to the first frame of your animation (index zero).

Yay zero-based arrays!