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:
#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:
#-------------------------------------------------
#
# 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