【发布时间】:2012-01-20 01:03:17
【问题描述】:
第一次在 C# 中尝试 XNA Framework..
按照本教程进行操作:http://www.uxmagic.com/blog/post/2010/08/17/e2809cHello-Worlde2809d-for-XNA-Game-Studio-40.aspx
一切正常,直到它说添加以下内容的那一行:
Vector2 playerPosition=vector2.zero;
在此行之前,我可以显示我的纹理,用 esc 关闭窗口。等等,整个事情看起来相当简单。
但是当我写完整个代码时,启动游戏给我这个错误......
The name 'vector2' does not exist in the current context
我错过了导入还是什么?谢谢 !这是完整的代码,因为它显然不在实际的网站上。
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();
}
}
}
【问题讨论】:
标签: c# visual-studio xna