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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - unranked86

Pages: 1 2 [3]
31
General / Theory behind a simple GUI
« on: August 01, 2011, 01:53:40 pm »
Quote from: "Nexus"

If you declare the destructor, you usually also have to declare copy constructor and copy assignment operator (Rule of the Big Three). But I don't think in your example there is a need for a manually-defined destructor, so just omit it.


Heh, thanks for pointing that out! :) After reading that rule, I realized that my current project is full of errors, and I just mindlessly use raw pointers, new and delete, in constructors and destructors respectively, without declaring copy constructors and assignment operators, and I thought I'm doing the right thing. It's about time I start fixing them :)

32
General / Theory behind a simple GUI
« on: July 31, 2011, 05:22:30 pm »
Based on your advice about the OnEvent() I rewrited the MenuSystem class, and it is just working perfect :) Now every MenuEntry has a "real label" which is an enum. So I add a new entry like this:
Code: [Select]

Test.AddMenuEntry("New Game", NEW);
Test.AddMenuEntry("Load Game", LOAD);
Test.AddMenuEntry("Options", OPTIONS);
Test.AddMenuEntry("Exit Game", EXIT);

I modified the whole thing, so the MenuSystem automatically sets the position of all the entries on the screen, based on their order in the std::vector. (This is just a bonus thing, which I gained by refactoring the stuff :) )
And then, updating and drawing them is the same as before:
Code: [Select]

Test.UpdateEntries();
Test.DrawEntries(App);


Quote from: "Nexus"

In fact I think an event-based approach is better, or how do you make sure that IsSelected() is only once true? That is, if the mouse button is held down during multiple frames, how to avoid that multiple games are created?


Hopefully my state manager will take care of this problem. Technically, when a menu is selected, it returns a variable to the state manager and some other part of the application will get the control, so there is no chance that there will be multiple games created. But I see your point, and I will test it later, to make sure it does not happen.
Thank you very much, I gained a lot from this topic!

33
General / Theory behind a simple GUI
« on: July 31, 2011, 02:53:06 pm »
After re-reading what I wrote yesterday, I realized I was talking about a completely different thing what I actually have. I am terribly sorry about this, but I had some beers ;)

Well, I will try to explain the real thing this time.
So, I have a MenuEntry class like this:
Code: [Select]

class MenuEntry
{
public:
MenuEntry (std::string label, int x, int y, const sf::Font& font);
~MenuEntry ();

void SelectEntry ();
void DeSelectEntry ();
void Update (); // this function checks the IsSelected boolean, and changes the color of the sf::Text object
void Draw (sf::RenderTarget& target);

private:
bool IsSelected;
int mPosX;
int mPosY;
sf::Text mLabel;

};

And I create instances of it:
Code: [Select]

MenuEntry newGame(...);
MenuEntry exitGame(...);


But I want to make my life easier, so I created a manager-like class, called MenuSystem. So decided to store all my MenuEntry objects in a container, and then I can update and draw them with one line of code, instead writing:
Code: [Select]

menu1.Update();
menu2.Update();
....
menuN.Update();

menu1.Draw();
menu2.Draw();
....
menuN.Draw();

So at the moment I update and draw them like this:
Code: [Select]

MenuSystem test;

MenuEntry menu1, menu2 ....menuN;
test.AddEntry(menu1);
test.AddEntry(menu2);
....
test.AddEntry(menuN);

// in main loop
test.UpdateEntries();
test.DrawEntries();


This is still not the thing I really want. Because I have to add all MenuEntry objects to the manager by hand, which is not cool. But works. The real problem however is this: this MenuSystem class only stores, updates and draws the MenuEntry objects, but it doesn't know what they do. So I can't tell this manager to do something like this:
Code: [Select]

if "newGame" is selected, create a new game
if "exitGame" is selected, close the application

What I tried to do, searching in the vector with find from <algorithm> didn't worked. Maybe I used in a wrong way.

I may be just overcomplicating this, but I'm stuck. Should I forget about the manager, and just hard code the menu ? But I really want a nice and reusable code.

34
General / Theory behind a simple GUI
« on: July 30, 2011, 10:26:28 pm »
Hi there everybody!
This might be a trivial question or problem. But I have a hard time figuring it out.

Actually I will just copy-paste (really) an e-mail adressed to Nexus, and I hope he doesn't mind it.

Here I go:

Quote
"Hi Nexus!

Let me introduce myself. I am Peter, unranked86 on the sfml forums. I'm a beginner at C++, and SFML, yet I find them very powerful.
I'm sorry to bother you in this way, and sorry about my english. Well, I shall get to point, I think.
Your work on Thor truly amazes me. It is a very good library, and I'm thinking about using it in my future projects.
But, something I really want to ask you is, how should I write a very basic GUI. By very basic, I mean, some menu entries, some buttons, and windows (widgets ?) What I'm interested is in, not concrete code, but some starting point.

What I have so far in theory, is something like this:

MenuSystem class, which manages all the MenuEntries, probably a std::vector or std::list. This class should allow me to add and remove MenuEntry objects, and control the behaviour of them. But, how can I achieve that ? I mean, I obviously can add and remove new items to a std::vector, but how can I make them to execute a certain "command". For example there is a menu with Newgame, Loadgame and Exitgame objects. Like the names suggests Newgame starts a new game, Loadgame loads a game, and Exitgame quits the application. These MenuEntries are just sf::Text objects basicaly wrapped in a class like this (not real code):

class MenuEntry
{
public:
 MenuEntry (unsigned int x, unsigned y, std::string label); // sets the sf::Text object's parameters
 ~MenuEntry ();
 virtual void Execute () = 0; // run the wanted code, like creating a new game
private:
 sf::Text mLabel;
};

This is just a base class, and I derive more classes from this. But my real problem is, which gives me a hard time, how do I tell the MenuSystem class about how to execute the right "command" in the Execute() function ? And how does it know which MenuEntry is selected ? Well, yes, the MenuEntry class needs an accessor funciotn 'bool IsSelected ()', which is true when the user selects it, but how does the code know this ?
I don't know if I'm clear enough. Actually I checked the source of cpGUI, but gained almost nothing from it."

35
I'm not sure, if there is any tutorial on making a pong game. But I think it's a fairly simple concept. There is
two paddle, and one ball, which is moving always, and the paddles are controlled by the players. It may sound
complicated, but it is fairly easy to implement.

Well, about the object-oriented programming...I recommend it. Sometimes, it can make your life easier. Once you
grasp the idea behind it, you will realize, that it can be very powerful.
This is a basic explanation about classes, and inheritation, BUT if you are not familiar with object oriented programming you should read about it.
Take a look at this very basic C++ tutorial for example. This site has some very nice explanation about the classes in C++. For further
reading I recommend the book "Beginning C++ through game programming" by Michael Dawson. I find it very useful. It is aimed
for beginners and I think, it's easy to understand.


Edit: P.S. Remember! Read,read, and read! ;)

36
Hi there!
First of all, please, excuse my english.

Well, I can understand, that you're a bit lost :) But don't worry. It's simple to start a pong-like game. I'm not
a very good programmer, in fact, I started learning C++ a few months ago, and later I picked up SFML.
Anyway. I assume, that you're using the 1.6 version of SFML. That's a good sign, that you finished most of the
tutorials, so you have some understanding what SFML does.

What little advice I can give you, is this:

1. (maybe the best method to start??)
Take the code (for example..) of the Shape tutorial, and try to modify it. Create a basic shape, add an
event handler, to allow you, to move this shape around the window. Later add bounds to it's movement, like
if the shape's position is greater than the width of the window, then don't change it's position. I hope, I'm
clear enough.

2.
Search the internet! :)
But this forum has already some nice tutorials, on how to start a game.
For example this

Read the documentation! It's very helpful!

I don't know if this helped you in any way. Actually, this is how I started to use SFML.

37
Graphics / Draw map from text file
« on: July 04, 2011, 05:46:47 pm »
I had a similar problem, then after a few minutes of searching I found this. Hope it helps.
But be aware, that code there is a bit flawed. Read the comments. Especially Part 4, otherwise you'll end up with some nasty memory leaks.

Pages: 1 2 [3]
anything