• XNA Animated Sprite Help
    6 replies, posted
Oh Hai... I am currently working on a resource for the community, it's a nice animated sprite class which should work... But it doesn't. Story of my life. Basically it should work like a sprite sheet, it draws a certain part of it and then moves to the next part. If you are still having trouble understanding it this is what my image looks like... [IMG]http://img130.imageshack.us/img130/8581/joekr.png[/IMG] F1 F2 F3 F4 F5 It should draw "F1" then "F2" then "F3" And so on and so forth. However it doesn't. It just renders "F1" And never updates. Here is my AnimatedSprite Class [URL]http://pastebin.com/m67eb5c3d[/URL] And my Joe Class [URL]http://pastebin.com/m5d97a4c2[/URL] I also have this warning: Warning 1 'Animated_Sprites.Joe.Update(Microsoft.Xna.Framework.GameTime)' hides inherited member 'Animated_Sprites.AnimatedSprite.Update(Microsoft.Xna.Framework.GameTime)'. Use the new keyword if hiding was intended. C:\Documents and Settings\Duncan\My Documents\Oli\XNA\Animated_Sprites\Animated_Sprites\Joe.cs 22 21 Animated_Sprites
iFrame should be set to 0 first so it'll start on the first frame rather than the second. Also, if (iAnimating == true) can be written as just: if (iAnimating). this bit: iTotalTime += theGameTime.ElapsedGameTime.Milliseconds; is adding the total elapsed time of the game to the variable each time, so it'll probably only ever be set to 200 once. You probably want to add 1 to the variable each frame instead of adding the elapsed time (make sure you change iFrame = 1 to 0 here as well). annnd lastly, your source rectangle (mDrawtangle) isn't being updated at all, so try changing this: [code] #region Update Frame if (iAnimating == true) { iTotalTime += theGameTime.ElapsedGameTime.Milliseconds; if (iTotalTime == 200) { iFrame++; iTotalTime = 0; } if (iFrame > iFrameCount) { iFrame = 1; } } #endregion [/code] to this: [code] #region Update Frame if (iAnimating) { iTotalTime++; if (iTotalTime >= 200) { iFrame++; if(iFrame > iFrameCount) iFrame = 0; iTotalTime = 0; mDrawtangle.X = iFrame * 34; } } #endregion [/code]
Hot Dayum it works... Thanks man, I just have 1 other problem (Which I am working on)... At the end of the animation he dissapears for 1 frame and then re-appears
try: if(iFrame >= iFrameCount) or something
Sussed it. Just working on getting the frame back to zero when it's not animating. Any hints/suggestions/ideas? [editline]08:59PM[/editline] [CODE] if(iAnimating == false) iFrame = 0; [/CODE] Should work, but it doesn't. Any Ideas?
where is that if statement in the code?
Here it is... [URL]http://pastebin.com/m72057cb0[/URL]
Sorry, you need to Log In to post a reply to this thread.