2016-09-08 3 views
0

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); 
} 
+0

값이 변경 되나요? 그리기 문제인 경우 Draw() 메서드를 표시해야합니다. – Sayse

+0

@Sayse draw() 메서드를 추가했으며 DCPlayer (Class) player.Update()에서 이동 값을 말하면 예 업데이트 됨 (예 : Position.X + = velocity;) – Kinggadino

답변

1

당신이 새로운 인스턴스에가 기회를 얻을 결코 의미 때마다 플레이어를 재 할당 : CurrentGameState는

편집 GameState라는 열거입니다 실제 위치를 사용하십시오. 표시된 코드를 보면 Draw 메서드에서이 행을 제거하면됩니다.

player = new DCPlayer(Content, level.grid, graphics.GraphicsDevice); 
+1

이동 한 플레이어 = 새 DCPlayer (Content, level.grid, graphics.GraphicsDevice); Initialize() 메서드에 추가하고 다른 클래스의 뷰를 변경하면 마침내이 작업을 수행 할 수 있습니다. 도와 주셔서 감사합니다! – Kinggadino

관련 문제