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

Author Topic: Input not declared  (Read 3703 times)

0 Members and 1 Guest are viewing this topic.

GroundZero

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
Input not declared
« on: August 22, 2011, 08:06:47 pm »
Hello guys,

I am following the tutorials on the website but I keep getting multiple errors.
I have been trying for ages to fix it but without any luck. I hope someone can help me out.

My code so far:

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

int main()
{
    // create a new window 800x600 resolution 32 bit
    sf::Window App(sf::VideoMode(800, 600, 32), "Zombie Madnezz");

    // attach the GetInput function to our window
    const sf::Input& Input = App.GetInput();

    // as long as this window is running
    while( App.IsOpened())
    {
        sf::Event Event;
        while (App.PollEvent(Event))
        {
            // if user closes the window stop running the program
            if(Event.Type == sf::Event::Closed)
            {
                App.Close();
            }

            // if user presses ESC button stop running the program
            if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Escape))
            {
                App.Close();
            }

            // set the objects for keyboard and mouse input
            bool LeftKeyDown  = Input.IsKeyDown(sf::Keyboard::Left);            // left arrow key
            bool RightKeyDown = Input.IsKeyDown(sf::Keyboard::Right);           // right array key
            bool SpacebarDown = Input.IsKeyDown(sf::Keyboard::Space);           // spacebar

            bool LeftMouseButton = Input.IsMouseButtonDown(sf::Mouse::Left);    // left mouse button
            bool RightMouseButton = Input.IsMouseButtonDown(sf::Mouse::Right);  // right mouse button

            unsigned int MouseCoordsX = Input.GetMouseX();                      // mouse position x-as
            unsigned int MouseCoordsY = Input.GetMouseY();                      // mouse position y-as

            // configure some character settings
            const float Speed = 50.f;
            float Left      = 0.f;                                              // only left and top are needed as we can
            float Top       = 0.f;                                              // calculate all with those three numbers

            // check if a key is pressed
            sf::Clock Clock;

            while (App.IsOpened())
            {
                float ElapsedTime = Clock.GetElapsedTime();
                Clock.Reset();

                if (App.GetInput().IsKeyDown(sf::Keyboard::Left))  Left -= Speed * ElapsedTime;
                if (App.GetInput().IsKeyDown(sf::Keyboard::Right)) Left += Speed * ElapsedTime;
                if (App.GetInput().IsKeyDown(sf::Keyboard::Up)) Top += Speed * ElapsedTime;
                if (App.GetInput().IsKeyDown(sf::Keyboard::Down)) Top -= Speed * ElapsedTime;
            }

        }

        // display the window
        App.Display();
    }

    return EXIT_SUCCESS;
}


My pro file:

Code: [Select]
#-------------------------------------------------
#
# Project created by QtCreator 2011-08-22T17:53:13
#
#-------------------------------------------------

QT       += core gui

TARGET = game
TEMPLATE = app


SOURCES += main.cpp

HEADERS  +=

FORMS    +=

LIBS += -L"C:\Program Files (x86)\SFML\lib" -lsfml-window -lsfml-graphics -sfml-system -sfml-main -sfml-audio

INCLUDEPATH = "C:\Program Files (x86)\SFML\include"


The error I get:

C:\Users\Ground Zero\Desktop\C++\leren\GAME\game-build-desktop\..\game\main.cpp:9: error: expected initializer before '&' token

C:\Users\Ground Zero\Desktop\C++\leren\GAME\game-build-desktop\..\game\main.cpp:30: error: 'Input' was not declared in this scope

C:\Users\Ground Zero\Desktop\C++\leren\GAME\game-build-desktop\..\game\main.cpp:53: error: 'class sf::Window' has no member named 'GetInput'

I have been following the tutorial of version 1.6. I am using version 2.0 though. I am on a Windows 7 Prof. machine with Qt Creator (newest version).

Hopefully someone can help me out.

Yours sincerely,


GZ

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Input not declared
« Reply #1 on: August 22, 2011, 08:14:49 pm »
sf::Input no longer exists in SFML 2.

http://www.sfml-dev.org/forum/viewtopic.php?p=34460#34460

Look now for sf::Mouse/Keyboard/Joystick.
SFML / OS X developer

GroundZero

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
Input not declared
« Reply #2 on: August 22, 2011, 08:32:28 pm »
Ohhh oke I see...
How do I fix it now? I dont complete understand it :$

I'll keep trying to figure it out, I just dont fully understand his post hehe :)
Fairly new to SFML ;)


EDIT:

Think i found it:

Code: [Select]

 if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Left))
 {
     // move left...
 }
 else if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Right))
 {
     // move right...
 }
 else if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Escape))
 {
     // quit...
 }

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Input not declared
« Reply #3 on: August 22, 2011, 08:37:15 pm »
I think you get the best information by looking at the documentations of sf::Mouse, sf::Keyboard and sf::Joystick. Hiura's link is more a design discussion thread.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

GroundZero

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
Input not declared
« Reply #4 on: August 22, 2011, 08:38:50 pm »
ahhh thats why lol, thanks very much for your fast replies!