SFML C# How do I switch between fullscreen?

561 Views Asked by At

I would like to switch between fullscreen and windowed mode. Is there some way to do that without restarting whole game?

2

There are 2 best solutions below

1
Tymo Tymo On BEST ANSWER

I would suggest calling the create method on your window (C++, but I'm sure it works in C# as well):

yourWindow->create(sf::VideoMode::getDesktopMode(), "Title", sf::Style::Fullscreen);
0
Hechelion On

Under C# you can't access ->create like C. you have to close the old RenderWindows and create a new one.

if (Keyboard.IsKeyPressed(Keyboard.Key.Enter) && Keyboard.IsKeyPressed(Keyboard.Key.LAlt) && !auxChangeStyle)
{
  auxStyle = (auxStyle == Styles.Default)? Styles.Fullscreen: Styles.Default;
  window.Close();
  window = new RenderWindow(new VideoMode(800, 600), "Title", auxStyle);
  window.Closed += (_, __) => window.Close(); //reassign the event handlers 
}