我刚开始学习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.
)当我按下右键时。为什么会发生?
问题在哪里? – pinckerman
@pinckerman对不起,我的意思是问为什么会出现这种错误。编辑它。任何方式我得到我的答案,MonoGame的错误。 – Zipzap
如果您不针对Windows进行部署,则Yap,GetData在Monogame上存在已知问题。 – pinckerman