XNA:对象未在屏幕上绘制
XNA: Object not drawn on screen
我以使用 XNA 在屏幕上绘制纹理而闻名。我只是无法让它工作。
我确实正确加载了纹理。
protected override void Draw(GameTime gameTime)
{
spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null,
selectedLevel.GetCamera().getViewMatrix(new Vector2(1.0f)));
graphics.GraphicsDevice.Clear(Color.Black);
foreach (MovableObject movableObject in selectedLevel.movableObjects)
{
if (movableObject is Enemy)
{
Enemy enemy = (Enemy)movableObject;
ThrowAttack attack = ((ThrowAttack)enemy.getAttack());
if (attack != null && attack.getThrowObject() != null)
{
attack.getThrowObject().Texture = TextureLoader.GetInstance().GetTexture(attack.getThrowObject().TextureName);
attack.getThrowObject().Animate(Direction.Right, gameTime);
attack.getThrowObject().Walk(Direction.Right, 2f);
attack.getThrowObject().Update(gameTime);
attack.getThrowObject().Draw(spriteBatch);
}
}
}
spriteBatch.End();
base.Draw(gameTime);
}
抽中攻击对象:
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, position, SpriteRectangle, Color.White, 0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0f);
}
上面.draw 方法中的纹理和位置变量有效。只是在 foreach 循环中没有特定的纹理。
有什么想法吗?
您的代码看起来是正确的,所以它可能正在被绘制。
确保没有其他东西(比如另一个精灵或背景)在它上面绘制。这将发生得如此之快,以至于它看起来根本没有被绘制。
我以使用 XNA 在屏幕上绘制纹理而闻名。我只是无法让它工作。 我确实正确加载了纹理。
protected override void Draw(GameTime gameTime)
{
spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null,
selectedLevel.GetCamera().getViewMatrix(new Vector2(1.0f)));
graphics.GraphicsDevice.Clear(Color.Black);
foreach (MovableObject movableObject in selectedLevel.movableObjects)
{
if (movableObject is Enemy)
{
Enemy enemy = (Enemy)movableObject;
ThrowAttack attack = ((ThrowAttack)enemy.getAttack());
if (attack != null && attack.getThrowObject() != null)
{
attack.getThrowObject().Texture = TextureLoader.GetInstance().GetTexture(attack.getThrowObject().TextureName);
attack.getThrowObject().Animate(Direction.Right, gameTime);
attack.getThrowObject().Walk(Direction.Right, 2f);
attack.getThrowObject().Update(gameTime);
attack.getThrowObject().Draw(spriteBatch);
}
}
}
spriteBatch.End();
base.Draw(gameTime);
}
抽中攻击对象:
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, position, SpriteRectangle, Color.White, 0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0f);
}
上面.draw 方法中的纹理和位置变量有效。只是在 foreach 循环中没有特定的纹理。
有什么想法吗?
您的代码看起来是正确的,所以它可能正在被绘制。
确保没有其他东西(比如另一个精灵或背景)在它上面绘制。这将发生得如此之快,以至于它看起来根本没有被绘制。