Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to make a turn-based roguelike engine thing for XNA. I'm basically porting the game over from a previous work I did using an SDL-based roguelike library called libtcod. How can I modify the basic XNA template thing to make the game not redraw the screen every frame, but, instead, when I want?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
356 views
Welcome To Ask or Share your Answers For Others

1 Answer

The correct method for doing this is to call GraphicsDevice.Present() whenever you want to draw the back buffer onto the screen.

Now the difficulty here is that the Game class automatically calls Present for you (specifically in Game.EndDraw), which is something you don't want it to do. Fortunately Game provides a number of ways to prevent Present from being called:

The best way would be to override BeginDraw and have it return false, to prevent a frame from being drawn (including preventing Draw and EndDraw from being called), like so:

protected override bool BeginDraw()
{
    if(readyToDraw)
        return base.BeginDraw();
    else
        return false;
}

The other alternatives are to call Game.SuppressDraw, or to override EndDraw such that it does not call base.EndDraw() until you are ready to have a frame displayed on screen.

Personally I would simply draw every frame.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...