MonoGame으로 타일 기반 그래픽 로그 라이크 게임을 만들고 있는데 입력을 처리 할 때 플레이어가 너무 빨리 움직입니다. 개별 키를 눌러 플레이어를 움직여도 응용 프로그램을 재생하는 것이 끔찍하게 재미 있지 않습니다.
게임 루프 사이에 시간을 어떻게 추가 할 수 있습니까? 사용하는 경우 Thread.Sleep
전체 프로그램을 내동댕이 및 모든 입력을 처리하지 않습니다.
결국 제가하기로 결정한 것은 다음과 같습니다.
게임 오브젝트를 구성 요소로 분리하고 있는데 하나는 Movement라고합니다. 움직임이 타일 기반이기 때문에 속도 나 벡터 등을 사용할 수 없었습니다.
코드는 간단하지만 여기에 모든 것을 포함하지 않았습니다.
public class Movement
{
// define a movement interval and store the elapsed time between moves
private double interval, elapsedTime;
public Movement(double interval)
{
this.interval = interval;
}
// called when arrow keys are pressed (player)
public void Move(Direction dir)
{
if(elapsedTime > interval)
{
// move
}
}
// called once per frame from the main class Update method
public void Update(GameTime gameTime)
{
if(elapsedTime > interval)
elapsedTime -= interval;
// add milliseconds elapsed during the frame to elapsedTime
elapsedTime += gameTime.ElapsedGameTime.TotalMilliseconds;
}
}
public enum Direction
{
LEFT,
RIGHT,
UP,
DOWN
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다