Click here to Skip to main content
15,885,278 members
Articles / Mobile Apps / Windows Phone 7

An XNA Animated Sprite Component for Windows Phone, PC, and Xbox

Rate me:
Please Sign up or sign in to vote.
4.78/5 (8 votes)
10 Jul 2011CPOL23 min read 42.2K   1.5K   22  
A proof of concept for an animated sprite component that I am developing to run in XNA projects on Windows Phone, PC, and Xbox. The component allows animation information to be a part of the project's content and is a step in the direction of allowing an artist to be completely over creating animati
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Microsoft.Xna.Framework.Graphics;

namespace J2i.Net.AnimatedSpriteLibrary
{
public class AnimatedSprite
{
    public string Name { get; set;  }
    public string PreferredTextureName { get; set;  }
    internal SpriteFont DebugFont { get; set;  }

    //Set this to true and set a debug font to see a frame
    //index next to an animation
    public bool ShowFrameNumber { get; set;  }
        
    [XmlIgnore]
    internal  Texture2D CurrentTexture { get; set;  }

    public void SetTexture(Texture2D sourceTexture)
    {
        CurrentTexture = sourceTexture;
    }
    //Setting a debug font and then setting ShowFrameNumber
    //to true will cause a frame index to appear next to an animation.
    public void SetDebugFont(SpriteFont font)
    {
        DebugFont = font;
    }


    public List<VisualState> VisualStateList { get; set;  }

    public AnimatedSprite()
    {
        VisualStateList = new List<VisualState>();
    }

    public AnimatedSpriteInstance CreateInstance()
    {
        return new AnimatedSpriteInstance(this);
    }        
}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
I attended Southern Polytechnic State University and earned a Bachelors of Science in Computer Science and later returned to earn a Masters of Science in Software Engineering. I've largely developed solutions that are based on a mix of Microsoft technologies with open source technologies mixed in. I've got an interest in astronomy and you'll see that interest overflow into some of my code project articles from time to time.



Twitter:@j2inet

Instagram: j2inet


Comments and Discussions