C# と XNA は初めてです。私の目標は、Sprite クラスから継承し、pongSprite、paddleSprite などのクラスを作成することです...コンストラクターでエラーが発生します。スプライト クラスを拡張し、スプライト クラスの変数とオブジェクトを :base() に配置しました。
これが私のコードです:
**
- Sprite.cs
**
namespace SimplePong
{
/// <summary>
/// This is a game component that implements IUpdateable.
/// </summary>
public class Sprite : DrawableGameComponent
{
protected string id;
protected Texture2D texture;
//bounding box
//protected Rectangle sourceRectangle;
protected Rectangle destinationRectangle;
protected Color color;
protected Main game;
private Sprite pongBall;
public Sprite(Main game, string id, Texture2D texture,
Rectangle destinationRectangle, Color color)
: base(game)
{
this.game = game;
this.id = id;
this.texture = texture;
this.destinationRectangle = destinationRectangle;
this.color = color;
}
/// <summary>
/// Allows the game component to perform any initialization it needs to before starting
/// to run. This is where it can query for any required services and load content.
/// </summary>
public override void Initialize()
{
// TODO: Add your initialization code here
base.Initialize();
}
/// <summary>
/// Allows the game component to update itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
public override void Draw(GameTime gameTime)
{
game.spriteBatch.Begin();
game.spriteBatch.Draw(texture, destinationRectangle, color);
game.spriteBatch.End();
base.Draw(gameTime);
}
}
}
**
- ballSprite.cs
**
using Microsoft.Xna.Framework;
namespace SimplePong
{
public class BallSprite : Sprite
{
// public Main game;
public Sprite pongBall;
public BallSprite()
: base(Main game, string id, Texture2D texture,
Rectangle destinationRectangle, Color color)
{
}
public override void Initialize()
{
base.Initialize();
}
public override void Update(GameTime gameTime)
{
destinationRectangle.X += 2;
destinationRectangle.Y += 2;
base.Update(gameTime);
}
public override void Draw(GameTime gameTime)
{
base.Draw(gameTime);
}
}
}