Windows Phone 8 で Monogame を学習しています。Sprite
スプライト オブジェクトの基本クラスであるクラスには、次のメソッドがあります。
public void Draw(SpriteBatch batch)
{
batch.Draw(texture, Position, color);
DrawSprite(batch);
}
protected virtual void DrawSprite(SpriteBatch batch)
{
}
Car
クラスから派生したクラスがありSprite
ます。その中に私が持っている
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);
}
問題は、車のスプライトが 2 回描画されることです。外すと
batch.Draw(texture, Position, color);
Draw
クラスのメソッドからSprite
、ボタンの背景のように他のスプライトが描画されません。
私の質問は、存在するが存在しない場合にのみオーバーライドメソッドを呼び出す方法だと思います
batch.Draw(texture, Position, color);
の
public void Draw(SpriteBatch batch)
{
batch.Draw(texture, Position, color);
DrawSprite(batch);
}