简体   繁体   English

二维C#XNA游戏中的动画

[英]Animations in a 2D C# XNA game

I want to create a 2d game in C# using XNA. 我想使用XNA在C#中创建2D游戏。 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. 这样做的好处是,您可以轻松地将一些简单的物理原理和逆运动学与动画混合在一起(请看Jakobsen出色的Verlet动力学论文),用于固定武器,啤酒罐和装卸架等。这是相当先进的东西,比3D图形要容易得多,但是设计和实施仍然要花很长时间。

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. 使用SpriteBatch合成精灵(给英雄一把剑等)时,可以帮助做一件事的是某些Draw方法重载上的Origin参数。 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. 由于Origin是在源纹理比例中指定的,因此,如果以不同比例绘制精灵,则任何计算都将是有效的事件。

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. 您可能想看看XNA Game Studio附带的2D Platformer示例。 That can get you started. 那可以帮助您入门。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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