From http://xbox.create.msdn.com/en-US/education/tutorial/2dgame/creating_the_player it is indicated that this code will be used:
public int Width() { get { return PlayerTexture.Width; } } public int Height() { get { return PlayerTexture.Height; } }
However, the "get" accessory is not recognized at all. I get the following errors:
The name "get" does not exist in the current context.
As an operator, you can use only assignment, call, increment, decrement, and new object expressions.
I am missing the line 'using System. (Something) '? I have seen that it has been used successfully countless times investigating my problem, but I cannot find anyone who comes across the same thing.
I am using XNA Game Studio 4.0 with Microsoft Visual C # 2010 Express. This is my complete code for the Player.cs class:
using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace Shooter { class Player { private Texture2D PlayerTexture; public Vector2 Position; public bool Active; public int Health; public int Width() { get { return PlayerTexture.Width; } } public int Height() { get { return PlayerTexture.Height; } } public void Initialise(Texture2D texture, Vector2 position) { PlayerTexture = texture; Position = position; Active = true; Health = 100; } public void Update() { } public void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(PlayerTexture, Position, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); } } }
source share