2012-12-18 24 views
0

我試過這個教程,但收到多條錯誤消息。2D頭像的難點

http://what-when-how.com/xna-game-studio-4-0-programmingdeveloping-for-windows-phone-7-and-xbox-360/2d-avatars-using-render-targets-xna-game-studio-4-0-programming/

我只是想畫一個2D頭像。

「世界」並不在當前上下文中存在的名稱
「觀看」不存在於當前上下文存在名稱
名稱「投影」不存在於當前上下文 名稱存在「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); 
    } 
} 

回答

3

本教程應該添加到已經繪製了頭像的基本教程中。例如。 this one

world,viewprojection是要使用的變換矩陣。 avatarRenderer是您可以從AvatarDescription檢索的渲染器。