1) why wouldn't i just use using namespace sf; and not have to do sf:: every time? |
That's certainly an option. The reason I don't recommend it is because it defeats the point of having a namespace in the first place. The namespace is there to prevent accidental name conflicts. If you do
using namespace sf;
then the namespace gets flooded with
every identifier in sf. If you unknowingly use some identifier that sf uses you'll have issues.
2) is Text the type or the object? same with sometext? |
Text is a class. sometext is an object/instance of that class.
The way SFML works with drawing is you have several objects that an be drawn. Each object has characteristics, like a position on the screen, rotation, etc, etc. The Text class allows you to create one such object that displays some text. You can then move around 'sometext' as if it were a "thing", rotate it, assign it different colors, etc.
There are other classes like that, too. sf::Sprite is probably the most common. It can be used to drawn portions of an image file to the screen. But it works the same way. You create an sf::Sprite object, assign it a picture, position, rotation, what-have-you, and then you just draw it.
3) Is Draw the member function of myWindow? |
Yes. It's actually a member function of sf::RenderWindow (or one of its parent classes). myWindow is just an object of that class -- so you could create several windows and draw to each of them if you wanted.
One of the bigger differences between graphical programs and console programs is that the console manages the window for you. when you do
cout << whatever;
it just takes whatever you wanted and puts it on the window. And when you do
cin >> whatever
, it patiently waits for the user to input something, then when they're done, it gives it back to you. If the user clicks the X to close the program, or if they resize the window, your program doesn't care. It doesn't get any notice.
With graphical programs it's different. You are responsible for creating the window, and watching for things like the user wanting to close it. And respond to those events if you care about them (or you can ignore them if you don't care).
But the big part is input. The console makes your program wait around for the user to input stuff, but in a game, you would want other things to keep happening (enemies moving around, things animating, etc). So the overall flow is different. Instead of just saying
cin >> foo;
and waiting around for the user, you have event and real-time status systems that can be polled while your game does other things.
That page I linked previously has an example of one way to do this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
// Start the game loop
while (window.IsOpened())
{
// Process events
sf::Event event;
while (window.PollEvent(event))
{
// Close window : exit
if (event.Type == sf::Event::Closed)
window.Close();
}
// Clear screen
window.Clear();
// Draw the sprite
window.Draw(sprite);
// Draw the string
window.Draw(text);
// Update the window
window.Display();
}
|
This is a very simple game loop. It consists of 3 basic parts:
1) process any events
2) run game logic
3) draw the scene
Events are things like the user wanting to close the window (so you can intercept that and save their game -- or prevent them from closing it if the program is in a critical state), resize the window (so you can adjust what is drawn on screen), mouse clicks, keyboard presses, joystick activity, etc. As these things happen, they build up in a "queue" that SFML manages. Periodically you go through the queue and see what events have built up and respond to them. That's what the
while (window.PollEvent(event))
loop is doing. As you can see, all he's doing here is closing the window when the user wants to.
There isn't really any game logic in that example. But you could do things like move the text a pixel or two after that loop to have it appear to slowly move across the screen.
After that, you draw your scene. This is done by:
1) clearing the screen
2) drawing all your drawable objects (Text, Sprites, shapes, etc)
3) displaying it
Here, they are drawing 1 text and 1 sprite. So 2 things will be visible on screen.
Throw all that in a loop so that it will keep happening as long as the window is open. Each time it runs, you move the player a little bit, move the enemies a little bit, etc. So the world keeps on changing as the program runs.
4) and my biggest question is why if SFML can make classes do all these things, wouldnt you just do them yourself... |
The same reason you use std::vector or std::iostream (cout). Those are classes too.
SFML made them to make it easier for you, so you don't have to reinvent the wheel. You can just use its simplified interface to make your game.
You
could redo it all from scratch if you really wanted, but then you'd have to worry about portability issues, and it would introduce bugs, etc, etc.
then you would understand what each class is, why it is, etc. |
It's easy to understand each class. There's no shortage of documentation on SFML. The website lists all the available classes, all their functions, and often gives examples of how to use them. If you don't understand it, you can post on the forums (either this forum or the SFML forum) and you'll get a response pretty quick.
i seem to have only one explanation at their website and everyone tells me to go to the tutorials that i didnt understand in the first place. |
I'm trying to remedy that. If you still have confusions or questions, you can post and I'm happy to help if I have the time.
i would see cout << and know that it is being outputted to screen |
in SFML, if you see
window.Draw(foo);
you know that 'foo' is being drawn to 'window'. It's not any more complicated, it's just different.
same with cin >> for input |
If you see
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Left))
you know the user is currently pressing the Left arrow key. Reference and examples:
http://sfml-dev.org/documentation/2.0/classsf_1_1Keyboard.php
in console to display output is cout and in SFML it is____, but i do not see such |
Remember you have to actually create and manage the window yourself in SFML. The console does that for you automatically in console programs. That previous link shows how to do it:
|
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
|
That's all it takes. That line of code gives you 'window', which is an 800x600 pixel window, whose title is "SFML window". You can then draw to that window whatever you want with
window.Draw( whateveryouwant );
another thing i dont understand is why would they tell noobies to start at console |
Beats the hell out of me. I never advocated that. IMO you're much better off starting with what your interests are. If you are interested in making games, then starting with the console is a dumb move, IMO.
I've debated this a few times on the boards. Some people disagree with me, but I stand by that.
cuz then it seems you have to relearn everything? |
Yup. It's a huge waste of time and effort. Of all the things you have to learn to make console programs, very little of it transfers over to the world of gaming. I've been saying this for years.