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

Author Topic: Event  (Read 10203 times)

0 Members and 1 Guest are viewing this topic.

Broken

  • Newbie
  • *
  • Posts: 26
    • View Profile
Event
« on: November 14, 2009, 09:34:11 pm »
Hi! I'm new here and I need help I start with tutorials
Now I working with event handling
Code: [Select]
#include<SFML/Window.hpp>
int main()
{
sf::Window App(sf::VideoMode(800, 600, 32), "SFML Window");
bool Running=true;
while(Running)
{
App.Display();
}
while (App.IsOpened())
{
    sf::Event Event;
    while (App.GetEvent(Event))
    {
        // Window closed
        if (Event.Type == sf::Event::Closed)
            App.Close();

        // Escape key pressed
        if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
            App.Close();
    }
}
return EXIT_SUCCESS;
}



when I compile and build code I get window but when I press Esc or X it can't close window
sry on my english I hope that you understand me

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Event
« Reply #1 on: November 14, 2009, 10:12:06 pm »
That's definitely not in the tutorial. ;)

You have two loops and you never get out of the first one.

Broken

  • Newbie
  • *
  • Posts: 26
    • View Profile
Event
« Reply #2 on: November 14, 2009, 10:25:20 pm »
Yes that is not from tutorial but that is code from tutorial can you correct what is wrong

Dominator

  • Newbie
  • *
  • Posts: 37
    • View Profile
Event
« Reply #3 on: November 14, 2009, 10:49:17 pm »
You have to put the event loop in the main loop. I'd do it like this:

Code: [Select]

  while (Running && App.IsOpened()) //main loop
  {
     App.Display();

     while (App.GetEvent(Event)) //event loop
     {
        //handle events
     }
  }


You should acquire some basic knowledge in programming first, loops are very fundamental.

Broken

  • Newbie
  • *
  • Posts: 26
    • View Profile
Event
« Reply #4 on: November 15, 2009, 01:33:08 am »
thx

Broken

  • Newbie
  • *
  • Posts: 26
    • View Profile
Event
« Reply #5 on: November 15, 2009, 04:29:54 pm »
I have problem with time handling when i compile and run code i get this error
Code: [Select]
sfml.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Clock::Reset(void)" (__imp_?Reset@Clock@sf@@QAEXXZ) referenced in function _main
sfml.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: float __thiscall sf::Clock::GetElapsedTime(void)const " (__imp_?GetElapsedTime@Clock@sf@@QBEMXZ) referenced in function _main
sfml.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Clock::Clock(void)" (__imp_??0Clock@sf@@QAE@XZ) referenced in function _main
C:\Documents and Settings\Valentin\My Documents\Visual Studio 2008\Projects\sfml-timehandling.cpp\Debug\sfml-timehandling.cpp.exe : fatal error LNK1120: 3 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Valentin\My Documents\Visual Studio 2008\Projects\sfml-timehandling.cpp\sfml-timehandling.cpp\Debug\BuildLog.htm"
sfml-timehandling.cpp - 4 error(s), 0 warning(s)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Event
« Reply #6 on: November 15, 2009, 04:46:02 pm »
This is explained in the tutorial. There are even screenshots to show what to do in the project's settings.
Laurent Gomila - SFML developer

Broken

  • Newbie
  • *
  • Posts: 26
    • View Profile
Event
« Reply #7 on: November 15, 2009, 05:05:46 pm »
in inputa I add sfml-window.lib in preprocesor SFML_DYNAMIC, I even add sfml-window.dll and sfml-system.dll in folder where is my project

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Event
« Reply #8 on: November 15, 2009, 07:06:43 pm »
sf::Clock is defined in sfml-system.lib.
Laurent Gomila - SFML developer

Broken

  • Newbie
  • *
  • Posts: 26
    • View Profile
Event
« Reply #9 on: November 15, 2009, 07:13:13 pm »
so in input i must put sfml-system.lib not sfml-window.lib why in tutorial about event handling is not included in source code <SFML/System.hpp>

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Event
« Reply #10 on: November 15, 2009, 07:17:11 pm »
Because System.hpp is included by Window.hpp.
Laurent Gomila - SFML developer

Broken

  • Newbie
  • *
  • Posts: 26
    • View Profile
Event
« Reply #11 on: November 15, 2009, 08:08:21 pm »
you say that in input always  must be sfml-system.lib ok i will try later because i have some work to do now

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Event
« Reply #12 on: November 15, 2009, 09:18:04 pm »
Quote from: "Broken"
you say that in input always  must be sfml-system.lib
Hmm, I don't know if I understand this right, but input handling is part of the Window package (the headers of which include the System package).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Event
« Reply #13 on: November 15, 2009, 11:14:25 pm »
I think he was talking about the "input libraries" field of the linker settings in Visual Studio ;)
Laurent Gomila - SFML developer

Broken

  • Newbie
  • *
  • Posts: 26
    • View Profile
Event
« Reply #14 on: November 15, 2009, 11:40:44 pm »
I try now and it doesn't work
I do this
file>new project>win32 console app.>source file>add new .cpp file>project>properties>c++>preprocessor>preprocessor definitions>where i write SFML_DYNAMIC; it looks like this "SFML_DYNAMIC;WIN32;_DEBUG;_CONSOLE">then linker>input>additional dependencies>sfml-system.lib>OK

I put sfml-system,-graphics dlls in folder where is project
and put this code in file .cpp

Code: [Select]
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>


////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            // A key has been pressed
            if (Event.Type == sf::Event::KeyPressed)
            {
                // Escape key : exit
                if (Event.Key.Code == sf::Key::Escape)
                    App.Close();

                // F1 key : capture a screenshot
                if (Event.Key.Code == sf::Key::F1)
                {
                    sf::Image Screen = App.Capture();
                    Screen.SaveToFile("screenshot.jpg");
                }
            }
        }

        // Clear the screen with red color
        App.Clear(sf::Color(200, 0, 0));

        // Display window contents on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}

and build and then i get errors

 what is wrong?
Code: [Select]
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::RenderWindow::~RenderWindow(void)" (__imp_??1RenderWindow@sf@@UAE@XZ) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::Display(void)" (__imp_?Display@Window@sf@@QAEXXZ) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::RenderTarget::Clear(class sf::Color const &)" (__imp_?Clear@RenderTarget@sf@@QAEXABVColor@2@@Z) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)" (__imp_??0Color@sf@@QAE@EEEE@Z) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Image::~Image(void)" (__imp_??1Image@sf@@QAE@XZ) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Image::SaveToFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)const " (__imp_?SaveToFile@Image@sf@@QBE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class sf::Image __thiscall sf::RenderWindow::Capture(void)const " (__imp_?Capture@RenderWindow@sf@@QBE?AVImage@2@XZ) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::Close(void)" (__imp_?Close@Window@sf@@QAEXXZ) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::GetEvent(class sf::Event &)" (__imp_?GetEvent@Window@sf@@QAE_NAAVEvent@2@@Z) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::IsOpened(void)const " (__imp_?IsOpened@Window@sf@@QBE_NXZ) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::RenderWindow::RenderWindow(class sf::VideoMode,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned long,struct sf::WindowSettings const &)" (__imp_??0RenderWindow@sf@@QAE@VVideoMode@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@KABUWindowSettings@1@@Z) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (__imp_??0VideoMode@sf@@QAE@III@Z) referenced in function _main
C:\Documents and Settings\Valentin\My Documents\Visual Studio 2008\Projects\sfml_grap.cpp\Debug\sfml_grap.cpp.exe : fatal error LNK1120: 12 unresolved externals