Jump to content
  • Advertisement
Sign in to follow this  

XNA Animated Sprites

This topic is 3315 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know it's simple, but it's been a while since I've worked with XNA and I finally came up with this class that works with animated sprites. Here's the class (download from mediafire): Texture2DA.cs It's really simple to use too. You can either pass the constructor no arguments, and load it using the Load() function, or pass the loading arguments to the constructor. It needs a Texture2D of the sprite sheet, and two integers specifying how many rows and columns of sprites there are in the sheet. The Play() function advances the current frame by one, and the Draw() function draws the sprite and takes three arguments: the x/y coordinates (as integers), and the SpriteBatch to use. The last function, SetPlayLimit(), sets the limits of the sprite. For instance, if you only want the sprite to play the first 3 frames, you would call SetPlayLimit(1, 3) to have the sprite play from the first frame to the third frame and repeat. This entry it both to share the class and to ask for suggestions on improvement, so if you see something you think could be improved, comment here.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!