3

I just started to learn XNA/MonoGame and I encountered a weird exception.
The error says: The method or operation is not implemented.
And what's even more weird that a very similar code, almost the same, works. The only difference is that the other code is run on XNA and on another computer, and my code runs on MonoGame.

The code is supposed to make an animation from a sprite sheet.

Inside of my class, 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]);
            }
        }
    }

the idea behind is that there is a line of dots below the sprite sheet, with those dots i can make frames from the sprite sheet. Here is the data of the class 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

Here is the part that summons the methods above, in the main class of the 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);
    }

So the error occurs in this line:

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

in the method animate in the class Animate. ( The method or operation is not implemented.) When I press the right key. Why does that happens?

pinckerman
  • 4,115
  • 6
  • 33
  • 42
Zipzap
  • 37
  • 8
  • And where is the question? – pinckerman Oct 27 '13 at 12:21
  • @pinckerman Sorry, I meant to ask why does that error occurs. Edited it. Any way i got my answer, MonoGame's bug. – Zipzap Oct 27 '13 at 16:40
  • Yap, GetData has known problems on Monogame if you don't deploy for Windows. – pinckerman Oct 27 '13 at 17:32
  • What platform are you targeting? On mobile devices getting the texture data is going to be a very slow operation, so even if you do get it working this way it may still be an issue. Have you considered reading the bitmap another way? Or perhaps storing the data as a list of coordinates instead. – craftworkgames Oct 30 '13 at 23:22

1 Answers1

1

Quite honestly that is a big difference, between XNA and a port of it.

A NotImplementedException does exactly what it suggest, it is thrown when a method or operation has not been implemented.

Nothing appears to be documented much about this, but it has been reported to the MonoGame bug tracker and is assigned to a developer for the 3.x release.

Using the SharpDX version however, this error does not exist.

Cyral
  • 13,999
  • 6
  • 50
  • 90
  • Actually this question has been asked a number of times on stackoverflow already, and it's also discussed quite a bit in the MonoGame team.. for example here.. https://github.com/mono/MonoGame/issues/1091 – craftworkgames Oct 30 '13 at 23:26