从
http://xbox.create.msdn.com/en-US/education/tutorial/2dgame/creating_the_player开始,指示使用此代码:
public int Width() { get { return PlayerTexture.Width; } } public int Height() { get { return PlayerTexture.Height; } }
但是,“get”访问器似乎根本不被识别.我收到以下错误:
>当前上下文中不存在名称“get”.
>只能将赋值,调用,递增,递减和新对象表达式用作语句.
我错过了’使用系统.(某事)’线路吗?我在调查我的问题时已经成功地使用过无数次,但我找不到任何碰到同样事情的人.
我正在使用XNA Game Studio 4.0和Microsoft Visual C#2010 Express.这是我的Player.cs类的完整代码:
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); } } }