Manual control over when to redraw the screen

前端 未结 2 1165
隐瞒了意图╮
隐瞒了意图╮ 2020-12-17 03:48

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

相关标签:
2条回答
  • 2020-12-17 04:34

    You don't need to inherit from Game class, it is entirely optional. You can write your own class which redraws the screen only when you want. There's some useful code in the class though, so you can use Reflector to copy code from there and then change its logic.

    0 讨论(0)
  • 2020-12-17 04:48

    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.

    0 讨论(0)
提交回复
热议问题