2

XNA/MonoGame の学習を始めたばかりで、奇妙な例外に遭遇しました。
エラーには次The method or operation is not implemented.
のように書かれています。唯一の違いは、他のコードは XNA と別のコンピューターで実行され、私のコードは MonoGame で実行されることです。

このコードは、スプライト シートからアニメーションを作成することになっています。

私のクラスの中で、Animate

    public void set_state(string name, string state)
    {
        this.name = name;
        this.state = state;
    }

    public void animate(int frameIndex) 
    {
        this.frameIndex = frameIndex;
        this.animatedTexture = Game1.contentManager.Load<Texture2D>(name + '/' + state);

        prepare_frames();
        while (this.frameIndex > rectangles.Count )
        {
            frameIndex = frameIndex - rectangles.Count;
        }
        base.draw(animatedTexture, rectangles[frameIndex], origins[frameIndex]);
    }

    public void prepare_frames()
    {
        find_dots();
        find_rectangles();
        find_origins();
    }

    public void find_dots()
    {
        cols = new Color[animatedTexture.Width];
        lowestRectangle = new Rectangle(0, animatedTexture.Height - 1, animatedTexture.Width, 1);

        animatedTexture.GetData<Color>(0, lowestRectangle, cols, 0, animatedTexture.Width);
        for (int i = 0; i < cols.Length; i++)
        {
            if (cols[i] == Color.Black)
            {
                dots.Add(new Vector2(i, animatedTexture.Height));
            }
        }
    }

    public void find_rectangles()
    {
        for (int i = 0; i < dots.Count-2; i+=2)
        {
            rectangles.Add(new Rectangle((int)dots[i].X, 0, (int)dots[i+2].X - (int)dots[i].X, animatedTexture.Height-1));
        }
    }

    public void find_origins()
    {
        for (int i = 1; i < dots.Count; i++)
        {
            if (i%2 != 0)
            {
                origins.Add(dots[i]);
            }
        }
    }

背後にあるアイデアは、スプライト シートの下にドットのラインがあり、それらのドットでスプライト シートからフレームを作成できるということです。クラスのデータは次のAnimatedとおりです。

    #region data

    Texture2D animatedTexture;
    string name, state; // to determine the animated state.

    Rectangle lowestRectangle; // is the rectangle of the dot's.
    Color[] cols; // this array is for the colors on the dot's rectungle.
    List<Vector2> dots = new List<Vector2>(); // this list is for the dot's coordinates on the dot's rectungle.
    List<Rectangle> rectangles = new List<Rectangle>(); // this list is for the new rectungles, each rectungle is a diffirent frame from the sprite sheet.       
    List<Vector2> origins = new List<Vector2>(); // this list is for each origin point of the new retungles.

    int frameIndex;

    #endregion

MonoGame のメイン クラスで、上記のメソッドを呼び出す部分は次のとおりですGame1

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        spriteBatch.Begin();

        if (Keyboard.GetState().IsKeyDown(Keys.Right))
        {
            player.set_state("moshe", "run");
            player.animate(frameIndex);
            frameIndex++;
        }
        else
            player.draw();

        spriteBatch.End();

        base.Draw(gameTime);
    }

したがって、次の行でエラーが発生します。

animatedTexture.GetData<Color>(0, lowestRectangle, cols, 0, animatedTexture.Width); 

animateクラスのメソッドでAnimate。( The method or operation is not implemented.) 右キーを押したとき。なぜそれが起こるのですか?

4

1 に答える 1

1

正直なところ、これは XNA とそのポートの大きな違いです。

メソッドまたは操作が実装されていない場合にNotImplementedExceptionスローされます。

これについてはあまり文書化されていないようですが、MonoGame バグトラッカー3.xに報告されており、リリースの開発者に割り当てられています。

ただし、SharpDX バージョンを使用すると、このエラーは存在しません。

于 2013-10-27T12:44:03.200 に答える