SFML community forums

Help => Graphics => Topic started by: Programmy on November 16, 2018, 03:16:18 am

Title: SFML Game dev by example book question,how does this function work?
Post by: Programmy on November 16, 2018, 03:16:18 am
need help understanding this function,

void Window::Create(){
auto style = (m_isFullscreen ? sf::Style::Fullscreen: sf::Style::Default);
m_window.create({ m_windowSize.x, m_windowSize.y, 32 }, m_windowTitle, style);
}

I understand that the create function is used like this

m_window.create( sf::VideoMode(800, 600), "mywindow", style);

so how come there are three variables in the parameter enclosed with a curly brace?
the string m_windowTitle and style are there, but what is with the first parameters enclosed with the curly brace,

what is the 32 and what is it used for?

here is the rest of the code I condensed from the book


#include "Window.h"



Window::Window()

{

   Setup("test", sf::Vector2u(800,600));
}
Window::Window(const std::string& title,sf::Vector2u size)
{
   Setup(title, size);

}
void Window::Setup(const std::string& title,sf::Vector2u size)
{
   m_isDone = false;
   m_isFullscreen = false;
   m_windowSize = size;
   m_windowTitle = title;
   Create();

}



Window::~Window()
{
}

bool Window::IsDone()
{
   return m_isDone;
}

sf::RenderWindow * Window::GetRenderWindow()
{
   return &m_window;
}

void Window::BeginWindow()

   m_window.clear(sf::Color::Black);
}

void Window::EndWindow()
{
   m_window.display();
}
void Window::Create()
{
   auto style = (m_isFullscreen ? sf::Style::Fullscreen : sf::Style::Default);

   //m_window.create({ m_windowSize.x, m_windowSize.y, 32}, m_windowTitle, style);

   m_window.create( sf::VideoMode(800, 600), "mywindow", style);

}
void Window::Update()
{
   sf::Event event;
   while (m_window.pollEvent(event))
   {
      if (event.type == sf::Event::Closed)
         m_window.close();
   }



}
Title: Re: SFML Game dev by example book question,how does this function work?
Post by: eXpl0it3r on November 16, 2018, 07:24:09 am
If you check the documentation you see that sf::VideoMode has a third parameter for the constructor.

The curly-braces are just uniform initialization and thus call the constructor of sf::VideoMode.
Title: Re: SFML Game dev by example book question,how does this function work?
Post by: Programmy on November 18, 2018, 06:38:21 am
I see, now it makes sense