first time trying XNA Framework in C#..
followed this tutorial: http://www.uxmagic.com/blog/post/2010/08/17/e2809cHello-Worlde2809d-for-XNA-Game-Studio-40.aspx
Everything’s ok until the line where it says to add the following:
Vector2 playerPosition=vector2.zero;
Before this line, I can display my texture, close the window with esc. etc, the whole thing seems fairly straightfoward.
But when I got the whole code written, lauching the game give me this error…
The name 'vector2' does not exist in the current context
Am I missing an import or something ? Thanks ! Here’s the full code because it’s not on the actual website, obviously.
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();
}
}
}
That line. Change
vector2.zerotoVector2.ZeroC# is case-sensitive language which is the reason why “vector2.zero” doesn’t work.
Pretty much every C# library ( atleast Microsoft’s libraries ) uses these casing conventions:
http://msdn.microsoft.com/en-us/library/ms229043.aspx
Although, many people ( myself included ) use underscore (“_”) for private/protected instance variables.