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

Author Topic: Many events  (Read 4519 times)

0 Members and 1 Guest are viewing this topic.

Jimicro

  • Newbie
  • *
  • Posts: 31
    • View Profile
Many events
« on: February 18, 2010, 02:15:47 am »
Hello

Is there away you can have many different events?

Like different classes and functions.

sf::Event Run;
sf::Event Meny;

Like that?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Many events
« Reply #1 on: February 18, 2010, 03:45:27 am »
What do you want to achieve by doing this? There is probably another way. ;)

You normally only have one sf::Event instance, which doesn't live very long. Some related code in the main loop might look as follows:
Code: [Select]
sf::Event event;
while (renderWindow.GetEvent(event))
{
    // react to events here
}
// after the loop, the event isn't interesting anymore
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Jimicro

  • Newbie
  • *
  • Posts: 31
    • View Profile
Many events
« Reply #2 on: February 20, 2010, 07:28:35 am »
Quote from: "Nexus"
What do you want to achieve by doing this? There is probably another way. ;)

You normally only have one sf::Event instance, which doesn't live very long. Some related code in the main loop might look as follows:
Code: [Select]
sf::Event event;
while (renderWindow.GetEvent(event))
{
    // react to events here
}
// after the loop, the event isn't interesting anymore


okey, thx I only want a menu and don´t want to load the game before the menu. You now like a real game so I don´t will see the game in the background while I am in the menu.

But thanks I shall see what I can do now. And hopefully it will work.:)

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Many events
« Reply #3 on: February 20, 2010, 05:09:59 pm »
Quote from: "Jimicro"
I only want a menu and don´t want to load the game before the menu. You now like a real game so I don´t will see the game in the background while I am in the menu.


Perhaps you want something like this?
Pluma - Plug-in Management Framework

Jimicro

  • Newbie
  • *
  • Posts: 31
    • View Profile
Many events
« Reply #4 on: February 21, 2010, 12:35:34 am »
Quote from: "gsaurus"
Quote from: "Jimicro"
I only want a menu and don´t want to load the game before the menu. You now like a real game so I don´t will see the game in the background while I am in the menu.


Perhaps you want something like this?


yeah, but I didn´t got it to work :(

So I hopefully thought it was some easier way to handle many events.

Jimicro

  • Newbie
  • *
  • Posts: 31
    • View Profile
Many events
« Reply #5 on: February 24, 2010, 08:41:44 pm »
I have tried a lot now and I don´t gets it to work.

Code: [Select]
   //Screens preparations
    screen_0 s0;
    Screens.push_back (&s0);


There I get an error.

Quote
D:\Programmering\Screens\main.cpp||In function `int main(int, char**)':|
D:\Programmering\Screens\main.cpp|22|error: no matching function for call to `std::vector<cScreen*, std::allocator<cScreen*> >::push_back(screen_0*)'|
C:\Program\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\stl_vector.h|557|note: candidates are: void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = cScreen*, _Alloc = std::allocator<cScreen*>]|
||=== Build finished: 1 errors, 0 warnings ===|

This error I only get when I write:
Code: [Select]
class screen_0: public Screen
and if I get this code
Code: [Select]
class screen_0: public Screen
{
private:
    int alpha_max;
    int alpha_div;
    bool playing;
public:
    screen_0 (void);
    virtual int Run (sf::RenderWindow &App);
};


Here I get an error to if I write public Screen after the class.
Quote

D:\Programmering\Screens\screen_0.hpp|5|error: expected class-name before '{' token|
D:\Programmering\Screens\main.cpp||In function `int main(int, char**)':|
D:\Programmering\Screens\main.cpp|22|error: no matching function for call to `std::vector<cScreen*, std::allocator<cScreen*> >::push_back(screen_0*)'|
C:\Program\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\stl_vector.h|557|note: candidates are: void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = cScreen*, _Alloc = std::allocator<cScreen*>]|


I don´t now what to do, can it be some linking error?

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Many events
« Reply #6 on: February 24, 2010, 11:01:27 pm »
Code: [Select]
class screen_0: public Screen

Code: [Select]
//Screens preparations
    screen_0 s0;
    Screens.push_back (&s0);


Quote
error: no matching function for call to `std::vector<cScreen*, std::allocator<cScreen*> >::push_back(screen_0*)'
(...)
note: candidates are: void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = cScreen*, _Alloc = std::allocator<cScreen*>]


The error says it. Seems that you have a class named "cScreen", the error is saying that your Screens vector is of type std::vector<cScreen*>, and you're trying to add an element of type screen_0* (which base class is of type Screen, and not cScreen. Do you have a class cScreen and another named Screen  :?:
Pluma - Plug-in Management Framework

Jimicro

  • Newbie
  • *
  • Posts: 31
    • View Profile
Many events
« Reply #7 on: February 24, 2010, 11:18:47 pm »
Quote from: "gsaurus"
Code: [Select]
class screen_0: public Screen

Code: [Select]
//Screens preparations
    screen_0 s0;
    Screens.push_back (&s0);


Quote
error: no matching function for call to `std::vector<cScreen*, std::allocator<cScreen*> >::push_back(screen_0*)'
(...)
note: candidates are: void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = cScreen*, _Alloc = std::allocator<cScreen*>]


The error says it. Seems that you have a class named "cScreen", the error is saying that your Screens vector is of type std::vector<cScreen*>, and you're trying to add an element of type screen_0* (which base class is of type Screen, and not cScreen. Do you have a class cScreen and another named Screen  :?:


I have three classes, screen_0, screen_1 and cScreen

I have five files. main.cpp, screen.hpp, screens.hpp, screen_0.hpp, screen_1.hpp

Jimicro

  • Newbie
  • *
  • Posts: 31
    • View Profile
Many events
« Reply #8 on: February 25, 2010, 12:15:38 am »
I finally solved it:D

The problem was that I didn´t know where I should put the cScreen class, and I didn´t know that it was suppose do be called like the public Screen

So now its called class cScreen and public Screen, and it doesn´t say so in the tutorial, maybe it´s some kind of linking problem. But know it works perfect. and hopefully now I can make my game.

Thanks for ther help anyway :)

 

anything