LamptonWorm

Hi,

With regards to this article, does anyone have the graphic they are loading in or a similar example I whipped up a simple 48x16 .png anim strip but when I use the AnimatedSprite class, it only shows one frame - the first, then blank, then frame 1 and so on, not the other 3 frames.

I'm sure it's something simple I'm missing! I've entered the frame total as 3 by the way as I have 3 frames in that image.

Cheers,
Dylan.


Re: XNA Game Studio Express Animated Sprite - the MSDN example

Joel Martinez

I would put a breakpoint in the DrawFrame method and see what values are being calculated for the "sourcerect" every frame. Do they fall within the bounds of your texture \

I would also potentially look at the UpdateFrame method ... are you calling this method and passing in "(float)gameTime.ElapsedGameTime.TotalSeconds"




Re: XNA Game Studio Express Animated Sprite - the MSDN example

ProfEclipse

Also note that there is a bug in the article. The line:

Frame = Frame % (framecount - 1);

should be:

Frame = Frame % framecount;

With the "- 1", if framecount is 4, then you would get a value between 0 and 2, not the desired 0 and 3.





Re: XNA Game Studio Express Animated Sprite - the MSDN example

LamptonWorm

Thanks both.

It was probably just the end of a long day, but I was still a bit confused at how rectangle works - you can probably help me there too ;) - is the placement and size of the rectangle different to the content pasted 'into' the rectangle or can you do both in a single command

e.g. set up my drawing area to start at 0,0 and set its size to 16,16 - then using my image take a snap from say 16,0 to 32,16, and paste that at 0,0. Hope that makes sense, at least my head it appears to - hmm!

Cheers :)




Re: XNA Game Studio Express Animated Sprite - the MSDN example

ProfEclipse

Yes, that will work. The source rectangle determines the contents of the image to display, and the destination rectangle determines the location and size of the displayed image. And remember, a rectangle is defined as it's origin and size, not it's top-left and lower-right corners. So, in your example case, destination would be (0,0,16,16), and source would be (16,0,16,16).

 

 





Re: XNA Game Studio Express Animated Sprite - the MSDN example

LamptonWorm

Thanks.