Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML Game dev by example book question,how does this function work?  (Read 2083 times)

0 Members and 1 Guest are viewing this topic.

Programmy

  • Newbie
  • *
  • Posts: 19
    • View Profile
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();
   }



}
« Last Edit: November 16, 2018, 03:20:25 am by Programmy »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: SFML Game dev by example book question,how does this function work?
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Programmy

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: SFML Game dev by example book question,how does this function work?
« Reply #2 on: November 18, 2018, 06:38:21 am »
I see, now it makes sense