我知道用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循环中的特定纹理。
有什么想法吗?
答案 0 :(得分:1)
您的代码看起来是正确的,因此可能 被绘制。
确保没有其他内容(如另一个精灵或背景)正在覆盖它。这将很快发生,看起来根本就不会被绘制。