I am beginner in game development and trying to make a game called space craft but i have some problems and i can't define what they are so i have attached the error message with my code.If anybody can help it's appreciated.
Main.cpp
#include<iostream>
#include"Header.h"
using namespace std;
int main(){
Game game;
game.Run();
system("pause");
return 0;
}
Header.h
#include<SFML/Graphics.hpp>
using namespace sf;
class Game{
public:
Game();
void Run();
private:
const Time TimePerFrame = seconds(1.f / 60.f);
Time TimeSinceLastUpdate;
bool IsMovingUp, IsMovingRight, IsMovingLeft, IsMovingDown;
void HandlePlayerInput(Keyboard::Key key, bool IsPressed);
private:
RenderWindow window;
Texture Ptexture;
Sprite Player;
private:
void ProcessEvents();
void Update(const Time TimePerFrame);
void Render();
};
Definitions.cpp
#include<iostream>
#include<SFML/Graphics.hpp>
#include<SFML/System.hpp>
#include<SFML/Window/ContextSettings.hpp>
#include"Header.h"
using namespace std;
Game::Game(){
TimeSinceLastUpdate = Time::Zero;
window.create(sf::VideoMode(640, 480), "Game Application", Style::Default);
if (!Ptexture.loadFromFile("plane.png")){
cout << "Error !\n";
return;
}
Player.setTexture(Ptexture);
// Scalling the craft
Player.setScale(0.5, 0.5);
Player.setPosition(100.f, 100.f);
IsMovingDown = IsMovingLeft = IsMovingRight = IsMovingUp = 0;
}
and this is the error messsage
Error 4 error LNK1120: 3 unresolved externals c:\users\programmer\documents\visual studio 2013\Projects\GameDevelopment\Debug\GameDevelopment.exe
Error 1 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 "public: __thiscall Game::Game(void)" (??0Game@@QAE@XZ) c:\Users\programmer\documents\visual studio 2013\Projects\GameDevelopment\GameDevelopment\Definitions.obj
Error 2 error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::create(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (__imp_?create@Window@sf@@QAEXVVideoMode@2@ABVString@2@IABUContextSettings@2@@Z) referenced in function "public: __thiscall Game::Game(void)" (??0Game@@QAE@XZ) c:\Users\programmer\documents\visual studio 2013\Projects\GameDevelopment\GameDevelopment\Definitions.obj
Error 3 error LNK2019: unresolved external symbol "public: void __thiscall Game::Run(void)" (?Run@Game@@QAEXXZ) referenced in function _main c:\Users\programmer\documents\visual studio 2013\Projects\GameDevelopment\GameDevelopment\Main.obj
5 IntelliSense: no instance of constructor "sf::ContextSettings::ContextSettings" matches the argument list c:\Users\Programmer\Documents\Visual Studio 2013\Projects\GameDevelopment\include\SFML\Window\Window.hpp 89
6 IntelliSense: no instance of constructor "sf::ContextSettings::ContextSettings" matches the argument list c:\Users\Programmer\Documents\Visual Studio 2013\Projects\GameDevelopment\include\SFML\Window\Window.hpp 106
7 IntelliSense: no instance of constructor "sf::ContextSettings::ContextSettings" matches the argument list c:\Users\Programmer\Documents\Visual Studio 2013\Projects\GameDevelopment\include\SFML\Window\Window.hpp 133
8 IntelliSense: no instance of constructor "sf::ContextSettings::ContextSettings" matches the argument list c:\Users\Programmer\Documents\Visual Studio 2013\Projects\GameDevelopment\include\SFML\Window\Window.hpp 151
9 IntelliSense: no instance of constructor "sf::ContextSettings::ContextSettings" matches the argument list c:\Users\Programmer\Documents\Visual Studio 2013\Projects\GameDevelopment\include\SFML\Graphics\RenderWindow.hpp 76
10 IntelliSense: no instance of constructor "sf::ContextSettings::ContextSettings" matches the argument list c:\Users\Programmer\Documents\Visual Studio 2013\Projects\GameDevelopment\include\SFML\Graphics\RenderWindow.hpp 94
Earlier StackOverflow question (https://stackoverflow.com/questions/28099250/sfml-game-development-in-c). ;)
Error 3 error LNK2019: unresolved external symbol "public: void __thiscall Game::Run(void)" (?Run@Game@@QAEXXZ) referenced in function _main c:\Users\programmer\documents\visual studio 2013\Projects\GameDevelopment\GameDevelopment\Main.obj
You declare the function void Game::Run() (and call it), but you never define it.
Error 1 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 "public: __thiscall Game::Game(void)" (??0Game@@QAE@XZ) c:\Users\programmer\documents\visual studio 2013\Projects\GameDevelopment\GameDevelopment\Definitions.obj
Error 2 error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::create(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (__imp_?create@Window@sf@@QAEXVVideoMode@2@ABVString@2@IABUContextSettings@2@@Z) referenced in function "public: __thiscall Game::Game(void)" (??0Game@@QAE@XZ) c:\Users\programmer\documents\visual studio 2013\Projects\GameDevelopment\GameDevelopment\Definitions.obj
My guess is, you didn't properly follow the official tutorial (http://www.sfml-dev.org/tutorials/2.2/start-vc.php), so your configuration is somewhere wrong. Please provide the full build command (http://www.sfml-dev.org/faq.php#tr-grl-verbose-ide).
#include<iostream>
#include<SFML/Graphics.hpp>
#include<SFML/System.hpp>
#include<SFML/Window/ContextSettings.hpp>
#include"Header.h"
You should add a space between #include and <xyz> or "xyz".
using namespace std;
using namespace sf;
Don't do that. It will make it a lot harder to read your code, since you'll never know if that one class is now your own, one from SFML or one from the standard library, plus you can really quickly run into ugly name clashes.
Header.h
Definitions.cpp
You should name the source and header files after the class they define and declare and make sure to use a source and header file per class. Additionally I suggest to use the *.hpp extension instead of the *.h one, it makes more sense to have for C *.c and *.h and for C++ *.cpp and *.hpp, just ignore the default *.h Visual Studio gives you. For example: Game.hpp and Game.cpp
...
Game::Game(){
TimeSinceLastUpdate = Time::Zero;
window.create(sf::VideoMode(640, 480), "Game Application", Style::Default);
if (!Ptexture.loadFromFile("plane.png")){
cout << "Error !\n";
return;
}
...
}
Ouch. This is toxic.
So, this constructor will silently complete (the return statement above) without properly constructing the object - way to surprise the fck out of users of the class.
The whole point of a ctor is to fully construct a complete and functional object. Once the ctor completes, that's what clients (rightly) expect to have happened.
If the ctor cannot construct the object and this is known to be fatal to the application as a whole, then I'd say a call of abort(); or similar would be warented here. Then you at least get a nice crash dump.
If it is possible that clients of the class have ways to deal with objects failing to construct correctly, then throwing an exception they can catch seems like a reasonable aproach.
Just silently returning from the ctor on error, with a partially constructed object as the result, is not a good idea.