【发布时间】:2013-09-11 07:16:52
【问题描述】:
我正在 Windows Phone 8 上学习 Monogame。在我的 Sprite 类中,它是精灵对象的基类,我有以下方法
public void Draw(SpriteBatch batch)
{
batch.Draw(texture, Position, color);
DrawSprite(batch);
}
protected virtual void DrawSprite(SpriteBatch batch)
{
}
我有一个源自 Sprite 类的 Car 类。在里面我有
protected override void DrawSprite(SpriteBatch batch)
{
batch.Draw(texture, Position, null, Color.White, MathHelper.ToRadians(rotateAngle),
new Vector2(texture.Width / 2, texture.Height / 2), 1.0f,
SpriteEffects.None, 0.0f);
}
然后在我的MainGame 类中,我使用以下方法绘制屏幕
protected override void DrawScreen(SpriteBatch batch, DisplayOrientation displayOrientation)
{
road.Draw(batch);
car.Draw(batch);
hazards.Draw(batch);
scoreText.Draw(batch);
}
问题是汽车精灵被绘制了两次。如果我删除
batch.Draw(texture, Position, color);
从Sprite 类的Draw 方法中,没有像按钮背景那样绘制其他一些精灵。
我想我的问题是如何仅在存在但不存在时调用覆盖方法
batch.Draw(texture, Position, color);
在
public void Draw(SpriteBatch batch)
{
batch.Draw(texture, Position, color);
DrawSprite(batch);
}
【问题讨论】:
标签: c# windows-phone-8 xna sprite monogame