GameState.MainMenu에서 모든 것이 잘 작동하지만 btnPlay (DCButton Class)를 클릭하면 GameState.Playing으로 전환되지만 (맵/플레이어로드) GameState.Playing의 경우 애니메이션이 적용됩니다.XNA 4 오브젝트가 한번 움직이지 않는다 GameState가 주 메뉴에서 재생으로 변경되었습니다.
protected override void Update(GameTime gameTime)
{
MouseState mouse = Mouse.GetState();
switch (CurrentGameState)
{
case GameState.MainMenu:
if (btnPlay.isClicked == true) CurrentGameState = GameState.Playing;
btnPlay.Update(mouse);
if (btnOptions.isClicked == true) CurrentGameState = GameState.Options;
btnOptions.Update(mouse);
if (btnExit.isClicked == true) Exit();
btnExit.Update(mouse);
break;
case GameState.Options:
break;
case GameState.Playing:
player.Update();
// Exit();
break;
}
base.Update(gameTime);
}
DCPlayer (클래스) Update() 메서드는 키보드 입력 및 플레이어 위치 변경으로 구성됩니다. 나는 또한 이것을 시도했다 :
case GameState.Playing:
player.Position.X += 1; // <- Position is a Vector2
break;
그러나 이것도 스프라이트를 움직이지 않는다. 왜 이런 일이 일어날 지 아는 사람이 있습니까?
참고 : 그리기 방법에서 그리기()
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
switch (CurrentGameState)
{
case GameState.MainMenu:
spriteBatch.Draw(mmBackgroundTexture, mmBackground, Color.White);
btnPlay.Draw(spriteBatch);
btnOptions.Draw(spriteBatch);
btnExit.Draw(spriteBatch);
break;
case GameState.Options:
spriteBatch.Draw(mmBackgroundTexture, mmBackground, Color.White);
break;
case GameState.Playing:
int progress = level.GetLevelProgress();
level.level = progress;
level.LoadLevel(); // <- This is where the map gets loaded from the map file
level.Draw(spriteBatch, Content); // <- This is were the map gets rendered
player = new DCPlayer(Content, level.grid, graphics.GraphicsDevice); // <- Could this be the problem, I initialized it here because the grid only gets initialized when the map is loaded
player.Draw(spriteBatch, Content); // <- Draw player in grid using map information (Vector2 DCLevel.Start)
break;
}
spriteBatch.End();
base.Draw(gameTime);
}
값이 변경 되나요? 그리기 문제인 경우 Draw() 메서드를 표시해야합니다. – Sayse
@Sayse draw() 메서드를 추가했으며 DCPlayer (Class) player.Update()에서 이동 값을 말하면 예 업데이트 됨 (예 : Position.X + = velocity;) – Kinggadino