【发布时间】:2018-10-09 18:10:13
【问题描述】:
我最近进入了 xna 框架,但遇到了一个问题。 这是我的代码,它不起作用
// Constructor
public Player()
{
texture = null;
position = new Vector2(350, 900);
moveSpeed = 10;
textureTitle = "playerShip";
}
// Load
public void LoadContent(ContentManager Content)
{
texture = Content.Load<Texture2D>(textureTitle);
}
// Update
public void Update(GameTime gameTime)
{
KeyboardState curKeyboardState = Keyboard.GetState();
if (curKeyboardState.IsKeyDown(Keys.W))
{
position.Y = position.Y - moveSpeed;
textureTitle = "playerShip2";
}
if (curKeyboardState.IsKeyDown(Keys.S))
position.Y = position.Y + moveSpeed;
if (curKeyboardState.IsKeyDown(Keys.A))
position.X = position.X - moveSpeed;
if (curKeyboardState.IsKeyDown(Keys.D))
position.X = position.X + moveSpeed;
}
// Draw
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, position, Color.White);
}
玩家总是被画成“playerShip” (对不起我的英语)
【问题讨论】:
-
你必须再次调用 LoadContent()。