現在、ゲーム エンジンの言語を C++ から C# に変更中です。C++ では、クラス内に 2 つのクラスを継承するだけで簡単に処理できますが、C# ではこれが不可能であることがわかりました。代わりに、インターフェイスを使用する必要があります。
私は例を探し回りましたが、ここにはたくさんあることを知っています。私の場合、どのように実装できるかわかりません。
チュートリアルに従ってこのコードを生成したため、ポリモーフィズムに関する私の知識が間違っている可能性があることに注意してください。
C++ コード:
class TileMap : public sf::Drawable, public sf::Transformable
{
...
private:
//this virtual function is simply so we don't have to do window.draw(target, states), we can just do window.draw(instance)
//this is called polymorphism?
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
{
// apply the transform
//this isn't our method, i assume it's something in draw() by default.
//or this generates the finished quads in one image instead of multiple ones.
states.transform *= getTransform();
// apply the tileset texture
//this puts the texture on to what we're going to draw (which is converted in to a single texture)
states.texture = &m_tileset;
// draw the vertex array
target.draw(m_vertices, states);
}
}
私のタイルマップ クラスはクラスを継承しDrawable
ます。クラスを継承するstates.transform *= getTransform()
ために必要な手段Transformable
。
ただし、c++ とまったく同じように c# でこれを行うことはできません。両方のクラスを継承することはできません。これは、インターフェイスを使用する必要がある場所だと思います。
public interface Transformable{ }
public interface Drawable : Transformable{ }
Drawable クラスでは仮想描画関数を実装すると思いますが、実際には Transformable から getTransform 関数を実装していないため、このようにアクセスする方法がわかりません。
ここで提供した関数でインターフェイスを使用してこれを行う方法を教えてください。
ありがとう。