我尝试了本教程,但收到了多条错误消息。
我只是想画一个2D头像。
当前情境中不存在“世界”这一名称 当前上下文中不存在名称“view” “投影”这个名称在当前上下文中不存在 “avatarRenderer”这个名称在当前上下文中不存在 当前上下文中不存在名称“avatarAnimation” 如何修复错误?
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
RenderTarget2D renderTarget;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
renderTarget = new RenderTarget2D(GraphicsDevice, 512, 512, false, SurfaceFormat.Color, DepthFormat.Depth16);
projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, 1, 0.01f, 200.0f);
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.SetRenderTarget(renderTarget);
GraphicsDevice.Clear(Color.Transparent);
avatarRenderer.World = world;
avatarRenderer.View = view;
avatarRenderer.Projection = projection;
avatarRenderer.Draw(avatarAnimation);
GraphicsDevice.SetRenderTarget(null);
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
spriteBatch.Draw(renderTarget, Vector2.Zero, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
答案 0 :(得分:3)
本教程应该添加到已经绘制头像的基础教程中。例如。 this one
world
,view
和projection
是要使用的转换矩阵。 avatarRenderer
是您可以从AvatarDescription
检索的渲染器。