XNA Tutorials, Samples and Thoughts
Catalin Zima
Microsoft XNA MVP
Posts by Catalin Zima
Chickens Can’t Fly is Live!
Feb 15th
Chickens Can’t Fly, the Must Have Game of the week on Windows Phone 7 is now purchaseable! Get it with one of the links below.
The game was developed by me and my wonderful team over at AmusedSloth!
Enjoy!
2D Pie Drawing updated to 4.0
Sep 20th
UberGeekGames just provided me with an version of the Pie Drawing sample, updated to XNA 4.0
You can find it on the sample’s page, or download it directly from here.
Enjoy!
2D Skeletal Animations
Jun 14th
What is your preferred way of doing animations in 2D?
Most of you will probably answer “spritesheets”, and you’d be right. Creating animations using spritesheets is quick, easy, there are helpful resources on the net and if you work with an external artist, he only needs to give you the individual frames of the animation (which also makes his life easy).
You would want to have a framerate of at least 12 for your animations, and you soon end up with something like this:
And with minimal effort, you can write code that loads this and displays it as an animation [SpriteSheetAnimation.zip]
All is well in the world, until you realize your game needs LOTS of animations and the memory consumption goes way up, together with the time required to load all the data. Also, to limit the size, you need to limit yourself to a low FPS for the animation (like 12), which also means the animation doesn’t look as smooth as you’d like. This is where skeletal animation comes in.
When using skeletal animation, the animation is composed of several bones which are connected to one another. Affecting a bone also affects all of its children. By composing different transformations on each bone, you obtain different poses for the skeleton.
Now, if you define keyframes with certain transformations for a point in time for each of the bones in the skeleton, you can interpolate between the keyframes to obtain a smooth transition and thus animate the skeleton.
In the attached code, I used a class named Transformation, which contains data about 2D transformations, like translation, rotation and scale. Then, a Keyframe is defined by a frame number and one such Transformation. A collection of Keyframes defines a KeyframeAnimation. Finally, a SkeletonAnimation is a collection of KeyframeAnimations, one for each bone in the skeleton.
Separately, I use a Skeleton, which keeps a list of Joints that define the hierarchy of bones in the skeleton. Each bone is then assigned a certain texture, like the ones below:
Each of the parts are individually animated relative to their parent bone, and thus the animation is obtained. In the sample, the animation is stored in two XML files that are loaded directly into a Skeleton (see machine_skeleton.xml ) and a SkeletonAnimation (see machine_animation.xml ) using the ContentPipeline at runtime. Here’s a video of the sample using skeleton animation:
As you can see, it runs much smoother than the initial frame-based animation. Also, looking at the resources used, the amount of texture data loaded into memory is significantly reduced (from 5.12 Mb to only 73Kb).
A word on how the XML file was generated. There are multiple options here.
- make a tool for editing animations, where you would set-up the positions of each frame and serialize it to disk using the IntermediateSerializer.
- let your artist create the animation in a software of is choice that can output the keyframes to XML, and then write a small program that converts that XML in the suitable format to be loaded by the Content Pipeline. For the animation above, I used a Flash animation created by a friend, exported the keyframes to ActionScript3 XML, and then converted that XML into the one you can see in the sample. (I won’t release that mini-tool however, since its code is a mess thrown together in about 1 hour).
A word of warning: while skeletal animation helps solve some problems with memory, loading times, smoothness, it is not a silver bullet. The amount of detail that can go into a normal sprite-sheet animation far surpasses what can be done with a skeletal animation. In skeletal animations you are limited to certain transformations on each ‘piece’ of the animation: translate, rotate, scale, flip. Meanwhile, frame-based animation allows the artist to add any kind of effect he likes.
I hope you enjoyed this sample. Feel free to leave any feedback and questions below.
To get the code, either download it directly (SkeletalAnimation.zip) or go to the sample’s page.
Until next time,
Happy coding!
License Updated
Jun 5th
Hi all,
I’ve updated the license for all code downloadable from this site. The licensing terms can be read here.
In short, the code is licensed under MIT, so you can use it freely (unless otherwise stated specifically).
However, I need to protect myself and my collaborators, so all content (images, sounds, etc) is not licensed, so you may not distribute it or use it in other circumstances than to be able to build and run the code as provided here for educational purposes.
These terms should satisfy most visitors on this site
MVP Summit 2011
Mar 13th
The first week of March I was together with a few other XNA MVPs at the Microsoft MVP Summit 2011 in Seattle.
I’d love to be able to tell you stuff we’ve learned there, or as Andy would also wish, to be able to tell you news about current issues you all know with XBLIG and the Creator’s Club AppHub site and forums. All guys present there were careful to repeatedly remind the team of the issues (especially George).
Of course, bound by our NDA’s we can’t share stuff we found out, but maybe we can tell you some things that might put you at ease.
- XBLIG is here to stay. Even if the WP7 side of things drew some focus away from the 360 side for a while, rest assured that the team is invested in XBLIG and they’re not letting it go anytime soon
- the previews we saw of what’s coming in the future of the phone side were great and you’ll love it all
- All teams are listening to feedback and doing their best to act on it
- Silence does not mean lack of interest on their part
Yes, Microsoft is not always moving as fast as we’d wish; Yes, there are pressing issues with the site; Yes, on some points they are behind the competition at this point… but I feel that YES, these (XNA, WP7, XBLIG) are awesome platforms to be on, only getting stronger, and having a great future.
On a personal note, this was a good summit. I had a great time with the other MVPs and met some great people in Microsoft, who I want to thank for their time and effort.
Also, I got a signed copy (thanks George and Chris) of this:
It’s a fantastic book, the writing style is fun, which makes it a real pleasure to read. And on the technical side, being written by these two guys, it’s probably the best you can get on the subject. The single complaint is that the tattoo didn’t make it on the cover.
Chickens Can Dream
Feb 27th
Well, this caught me off-guard…
When we submitted the game last Sunday, I was hoping the game would get through certification sooner, but apparently it decided to come out just as I was starting my long trip towards Seattle. I’m proud to say that Chickens Can Dream just went live on the Windows Phone 7 Marketplace on Friday.
Go ahead and download it (it’s free) if you haven’t already and let me know what you think
While Chickens Can Dream is just a milestone in the wonderful adventure that is the Chickens Can’t Fly project, it’s also a great achievement for me. While this is certainly not my first game, or not even the first game I’ve worked on that got published, I can certainly say it is the game I’ve put most of myself into, am most proud of and most excited about sharing with you (all 6 of you that still read my blog
).
It’s definitely not perfect yet, and we’re working on the next update for it as we speak (at least my team is, I’m on a plane flying over Canada), but our goal with Chickens Can Dream was to get it out there and get feedback on it.
Besides letting you know about the game and giving you the download link, I also wanted to take this opportunity to congratulate and thank my team and people that made this possible, so here goes:
- Razvan and Razvan - for all the brainstorming sessions where they helped refine my design and especially for all the code they wrote.
- Hashu - for the great art he created for the game and for suffering through our feedback on the art drafts
- Gabi and Flaviu - for the last few weeks helping us get highscores and online services in the game.
- Lidia - for helping me see errors in my designs every time she played whatever build I had on my phone (and for coming up to our floor to make us take breaks from time to time). Even though she’s a gamer, she was invaluable in ensuring the game is suited for a large non-gamer audience.
- Robert, Gabi and Claudiu- for trusting us and giving us the opportunity and resources to create this game.
- All people who played various builds of the game – for being test subjects.
Thank you all!
Download the game now because we want to know how to make Chickens Can’t Fly better!
Screen-space deformations in XNA for WP7
Jan 26th
I posted a new tutorial recently about applying deformations as a post-processing… process using only stuff available in the Reach profile, without any shaders. This configuration is useful for Windows Phone 7.
Go ahead and read the whole article here.
XNA 4.0 version of the Deferred Rendering code
Dec 28th
Roy Triesscheijn just posted an updated version of the code he obtained after following my Deferred Rendering tutorial.
You can read all about it on Roy’s blog, here.
So we now have a working 4.0 version of the tutorial.
Thanks, Roy!
Sgt. Conker
Oct 29th
What is Sgt. Conker? It is the new website for games development related articles, news, gossip and whole lot more.
Whenever you want to see something new on the XNA development front, give us a visit, or just subscribe to the site’s RSS feed.
I also take this opportunity to announce one of the upcoming features on Sgt. Conker, the Shader Challenges, where we’ll be challenging you to finish an incomplete shader, or fix a broken one, which we hope will be an interesting way for you to improve your HLSL skills. Stay tuned for this, because it’s comming in the near future, together with a whole lot more!




