Ok, so I'm getting into game development, and (despite what I said earlier) I'm using C++. I'm going to be using the amazing and incredible SFML library. I was watching CodingMadeEasy's tutorials on it, and he did the following code(I commented what I understand and don't understand):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
sf::RenderWindow window; // 1
window.create( sf::VideoMode(800,600), "My First SFML Game", sf::Style::TitleBar | sf::Style::Close ); // 2
This creates a new instance of the RenderWindow class found in the sf namespace called "window". Pretty simple stuff!
I understand most of this code, but this is what I made this topic for. I understand it up until the | bitwise operator. It creates a window with a size of 800x600 and the title of it is "My First SFML Game". Then we style the window so it has a close button, but hold up a second! Why do we do sf::Style::TitleBar | sf::Style::Close??? Why do we need the | symbol?? I don't understand!
Also, sorry for the extremely wide code section :( I can't fix that!
The comments in the code basically asked the question for me! So yeah! Please help! :)
You could always hit the carriage return/enter key...
Say you have two bits x and y. Bits are individual parts of a byte and can only hold two states: on or off (1 or 0 respectively).
The OR bitwise operator returns 1 if either x or y is 1.
In your case, the OR bitwise operator is used to flip on bitflags. Bitflags are like using an array or container of bools (though there is the <bitset> library that does the same).
Let's say the bytes of TitleBar and Close look lik 00010000 and 00000010 respectively. So, ORing them would look like:
0 0 0 1 0 0 0 0
| 0 0 0 0 0 0 1 0
0 0 0 1 0 0 1 0
The result is two bitflags switched on, so the internal code in sf::RenderWindow will know to include both a titlebar and a close button.
And found that 'TitleBar', 'Close', and others are actually numbers. So sf::style::TitleBar | sf::Style::Close is the same as 1 | 4. This returns the value 5 so this since there is no value 5 in the sf::Style namespace, this will then correspond to sf::Style::Default
The default style, which is a shortcut for Titlebar | Resize | Close
If you were not able to follow my rambling, I provided some links. Gl