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

Author Topic: SFML Game Development  (Read 3168 times)

0 Members and 1 Guest are viewing this topic.

Mahmoud Anwer

  • Newbie
  • *
  • Posts: 1
    • View Profile
SFML Game Development
« on: January 23, 2015, 06:32:10 am »
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
 

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: SFML Game Development
« Reply #1 on: January 23, 2015, 07:23:00 am »
You can pretty much ignore IntelliSense errors most of the time since it breaks a lot. As for your link errors, make sure you are linking sfml-graphics.

Also, the line:
window.create(...)
Why dont you just initialize it in the initialization list?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10882
    • View Profile
    • development blog
    • Email
Re: SFML Game Development
« Reply #2 on: January 23, 2015, 11:30:19 am »
Earlier StackOverflow question. ;)

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, so your configuration is somewhere wrong. Please provide the full build command.


#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
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: SFML Game Development
« Reply #3 on: January 23, 2015, 03:07:51 pm »
...
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.
« Last Edit: January 23, 2015, 03:31:02 pm by Jesper Juhl »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML Game Development
« Reply #4 on: January 25, 2015, 08:32:47 am »
I would also throw an exception. No need to abort in the constructor, it's the caller's choice how to deal with a failure. Uncaught exceptions automatically terminate the program. A handler in main() can also output error details, e.g. the exception object's what() method.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: SFML Game Development
« Reply #5 on: January 25, 2015, 09:58:58 am »
That (exception) would normally also be my preference. I only mentioned abort() since even that is better than continuing with a partially constructed object.

 

anything