Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# xna多级继承-无法访问基类属性_C#_Inheritance_Xna_Multi Level - Fatal编程技术网

C# xna多级继承-无法访问基类属性

C# xna多级继承-无法访问基类属性,c#,inheritance,xna,multi-level,C#,Inheritance,Xna,Multi Level,标题应该很清楚,我在访问具有多重继承的最低级别属性时遇到问题 对象A扩展对象B 对象B扩展对象C 对象C有一个我想从对象a访问的属性,但由于某种原因,我只能从对象B访问它。适用于变量和函数 确切地说,我正在使用一个定制的libbrary——“Windows游戏库(4.0)”。当我不使用图书馆时,我从来没有遇到过任何问题。唯一不同的是,我现在在库中的类上使用“public”关键字,否则我会得到一个“不可访问”的错误 代码: 对象A namespace示例游戏 { 班级:演员 { 公共玩家() {

标题应该很清楚,我在访问具有多重继承的最低级别属性时遇到问题

对象A扩展对象B 对象B扩展对象C

对象C有一个我想从对象a访问的属性,但由于某种原因,我只能从对象B访问它。适用于变量和函数

确切地说,我正在使用一个定制的libbrary——“Windows游戏库(4.0)”。当我不使用图书馆时,我从来没有遇到过任何问题。唯一不同的是,我现在在库中的类上使用“public”关键字,否则我会得到一个“不可访问”的错误

代码:

对象A
namespace示例游戏
{
班级:演员
{
公共玩家()
{

//大多数事情都发生在gameobject中这绝不是一个专家的答案,但是你可以总是从类B中的类C中暴露你想要的属性,从而从类A中的基访问它们


我相信有一个更优雅的解决方案,但只是一种镜像(或者它可能被称为隧道?)通过B的属性至少应该是可用的。

ExampleGame
命名空间中可能有一个
Actor
类,或者由玩家继承的using指令导入的某个命名空间。这与
GridEngine.objects
命名空间中的
Actor
类不同。

将您的类放入LINQPad,我可以从
Player
访问
GameObject
的成员,前提是他们至少有
受保护的
访问权限。这就是我所期望的。您可以从
Actor
访问
GameObject
成员是没有意义的,但不能从
Player
访问。我没有我想你的类在不同的项目中肯定存在构建问题,但我只是猜测,没有复制错误。在哪里定义了固定的?如果它应该在GameObject类中,并且你编译的代码中,我建议你以某种方式从不同的GameObject类继承。很可能你st在您的示例代码中漏掉了一些东西,但我想我会把它提出来。ExampleGame中没有Actor类,ExampleGame只有“Game”类(应用程序访问点)和Player类。这确实是可能的,但会让一切变得一团糟:(
    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();
    }

}
}
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;
        }
    }

}
}
    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);
    }
}

}