简体   繁体   中英

Animations in a 2D C# XNA game

I want to create a 2d game in C# using XNA. There should be stickmen who can wear different weapons like a pistol, a grenade or a rocket launcher. And those stickman also should be able to do other things, like drink a bottle of beer and stuff.. So how do you create and store these animations (drink a bottle of beer, walk, throw a grenade) and how can you tell them how to hold a weapon (pistol: in the hand, grenade: in the hand, but holding the arm behind them, rocket launcher: on the shoulder)? What's the best (simple and extensible) approach to this?

For stickmen, comes to my mind, skeletal animations with directly rendered bones. Such vector graphics would scale very well compared to sprites. Skeletal animation stores a tree of bones with lengths and angles, and interpolates between predefined keyframes. The advantage of this is that you can easily incorporate some simple physics and inverse kinematics that blend with the animations (take a look at Jakobsen excellent Verlet dynamics paper) for holding weapons, beer cans and mantling ledges, etc. This is fairly advanced stuff, much easier than 3D graphics, but it will still take you a long time to design and implement.

One thing that can help when compositing sprites (giving a hero a sword, etc) using SpriteBatch is the Origin argument on some of the Draw method overloads. It allows you to rotate around something other than the top left corner and can also help when positioning sprites that are of differing sizes. Since the Origin is specified in source texture scale, any calculations will be valid event if the sprites are drawn at a different scale.

What you're asking is a fairly broad question. You might want to have a look at the 2D Platformer sample that comes with XNA Game Studio. That can get you started.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM