방금 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]);
}
}
}
뒤에 아이디어는 스프라이트 시트 아래 점의 라인은 내가 스프라이트 시트에서 프레임을 만들 수있는 그 점으로, 있다는 것입니다. , Game1
여기
#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의 기본 클래스에서, 상기 방법 소환 부분이다 : 여기서 클래스
Animated
의 데이터이다
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);
}
그래서 에러이 발생 라인 : 클래스 Animate
의 방법 animate
에서
animatedTexture.GetData<Color>(0, lowestRectangle, cols, 0, animatedTexture.Width);
. (The method or operation is not implemented.
) 오른쪽 키를 누르면. 왜 그렇게됩니까?
그리고 질문은 어디에 있습니까? – pinckerman
@pinckerman 죄송합니다. 왜 그런 오류가 발생하는지 묻겠습니다. 편집했습니다. 어떤 식 으로든 나는 내 대답을 얻었고, MonoGame의 버그. – Zipzap
Windows 용으로 배포하지 않으면 GetData에 Monogame에 대한 알려진 문제점이 있습니다. – pinckerman