2013-10-27 52 views
2

我剛開始學習XNA/MonoGame和我遇到了一個奇怪的例外。
錯誤說:The method or operation is not implemented.
,什麼是更奇怪的是非常相似的代碼,幾乎是相同的,作品。唯一的區別是其他代碼在XNA和另一臺計算機上運行,​​我的代碼在MonoGame上運行。MonoGame的GetData實施例外

的代碼應該使從精靈表的動畫。

在我的課,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.)當我按下右鍵時。爲什麼會發生?

+0

問題在哪裏? – pinckerman

+0

@pinckerman對不起,我的意思是問爲什麼會出現這種錯誤。編輯它。任何方式我得到我的答案,MonoGame的錯誤。 – Zipzap

+0

如果您不針對Windows進行部署,則Yap,GetData在Monogame上存在已知問題。 – pinckerman

回答

1

坦白地說這是一個很大的區別,XNA和它的端口之間。

一個NotImplementedException不正是它表明,當一個方法或者操作尚未完成,實現了拋出。

似乎沒有任何文件記錄太多,但它已被報告給MonoGame bug tracker,並被分配給3.x版本的開發人員。

但是使用SharpDX版本,不存在這個錯誤。

+0

其實這個問題已經在stackoverflow上問了很多次了,在MonoGame團隊中也有相當多的討論..例如這裏.. https://github.com/mono/MonoGame/issues/1091 – craftworkgames