タイトルは明確にする必要があります。複数の継承を使用して最下位レベルのプロパティにアクセスするのに問題があります。
オブジェクト A はオブジェクト B を拡張します。オブジェクト B はオブジェクト C を拡張します。
オブジェクト C には、オブジェクト A からアクセスしたいプロパティがありますが、何らかの理由でオブジェクト B からしかアクセスできません。変数と関数の両方に適用されます。
カスタム ライブラリ - 正確には「Windows Game Library(4.0)」を使用しています。ライブラリを使用していないときは、これで問題はありませんでした。今までとの唯一の違いは、ライブラリ内のクラスで "public" キーワードを使用していることです。そうしないと、"アクセス不能" エラーが発生するためです。
コード内:
オブジェクト A
namespace ExampleGame
{
class Player : Actor
{
public Player()
{
//most things happen in gameobject<actor<this
MaxSpeed = new Vector2(10, 10);
Acceleration = new Vector2(5, 5);
Velocity = new Vector2(0, 0);
MaxJumpPower = 15;
}
override public void Update()
{
base.Update();
manageInput();
}
}
}
オブジェクト B
namespace GridEngineLibrary.objects
{
public class Actor : GameObject
{
public int MaxJumpPower;
public Actor()
{
canMove = true;
}
/// <summary>
/// moves the object but it's acceleration
/// </summary>
public void jump()
{
if (grounded == true)
{
Console.WriteLine("jump!");
Direction.Y = -1;
Velocity.Y = MaxJumpPower * -1;
}
}
}
}
オブジェクト C
namespace GridEngineLibrary.objects
{
public class GameObject
{
public Vector2 location;
public SpriteBatch spritebatch;
public Vector2 hitArea;
public AnimatedTexture graphic;
public Vector2 Velocity;
public Vector2 Acceleration;
public Vector2 MaxSpeed;
public Vector2 Direction;
public int Z = 1;
public bool canMove;
public GameObject()
{
spritebatch = SpriteManager.spriteBatch;
}
/// <summary>
/// set the animated texture
/// </summary>
/// <param name="location"></param>
/// <param name="size"></param>
/// <param name="TextureName">name of texture to load</param>
public void setAnimatedTexture(Vector2 location, Vector2 size, string TextureName,
int totalFrames, int totalStates, int animationSpeed = 8,
int spacing = 9)
{
graphic = new AnimatedTexture(location, size, TextureName);
graphic.isAnimated = true;
graphic.totalStates = totalStates;
graphic.totalFrames = totalFrames;
graphic.animationSpeed = animationSpeed;
graphic.spacing = spacing;
hitArea = size;
}
virtual public void Update()
{
graphic.update(location);
}
}
}