XNA Framework"Vector2"问题.*第一个计划......*

JFF*_*FFF 2 c# xna visual-studio

第一次在C#中尝试XNA Framework

遵循本教程:http://www.uxmagic.com/blog/post/2010/08/17/e2809cHello-Worlde2809d-for-XNA-Game-Studio-40.aspx

一切都没问题,直到它说要添加以下内容的行:

Vector2 playerPosition=vector2.zero;
Run Code Online (Sandbox Code Playgroud)

在此行之前,我可以显示我的纹理,用esc关闭窗口.等等,整个事情似乎相当直接.

但是当我写完整个代码时,推出游戏给我这个错误......

The name 'vector2' does not exist in the current context    
Run Code Online (Sandbox Code Playgroud)

我错过了一个导入或什么?谢谢 !这是完整的代码,因为它显然不在实际的网站上.

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame2
{

    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Texture2D playerTexture;
        Vector2 playerPosition = vector2.zero;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            playerTexture = Content.Load<Texture2D>("character1");
            //base.LoadContent();
        }

        protected override void UnloadContent()
        {

        }

        protected override void Update(GameTime gameTime)
        {

            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                this.Exit();

            if (Keyboard.GetState().IsKeyDown(Keys.Left))
                playerPosition.X--;

            if (Keyboard.GetState().IsKeyDown(Keys.Right))
                playerPosition.X++;

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin();
            //spriteBatch.Draw(playerTexture, Vector2.Zero, Color.White);
            spriteBatch.Draw(playerTexture, playerPosition, Color.White);
            spriteBatch.End();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 5

Vector2 playerPosition = vector2.zero;
Run Code Online (Sandbox Code Playgroud)

那条线.更改vector2.zeroVector2.Zero

C#是区分大小写的语言,这就是"vector2.zero"不起作用的原因.

几乎每个C#库(至少微软的库)都使用这些套管约定:

http://msdn.microsoft.com/en-us/library/ms229043.aspx

虽然,许多人(包括我自己)对私有/受保护的实例变量使用下划线("_").