In this tutorial project, we will build a fully working and functional but simple C++ game engine. All that the game engine will do is allow the player to control one object moving left and right on a background, however, once you have completed the project you will be able to use the example game object class,
Bob as a blueprint for adding as many other objects as you like. The tutorial won’t cover collision detection as that was discussed in the pong game and once you have read that tutorial it would be trivial to add this feature into the update function that we will be writing. Note that this really is a “simple” engine and future tutorials will expand and evolve this code to add more features. The long-term shortcomings of the engine are discussed at the end. What you do get with this simple game engine is a level of abstraction that will allow you to build a relatively complex game, without ending up in a tangled mess of code.
[widgets_on_pages id=”udemy_advert_cpp_1″][widgets_on_pages id=”udemy_code_details”]
Creating the simple game engine project in Visual Studio
To get started we need to create a new project in Visual Studio, complete with all the required properties to work with SFML. If you haven’t completed the Building your first SFML game project you will need to do that first in order for the next steps to work.
These next steps set up our new SFML C++ game engine project.
- Open Visual Studio and from the main menu choose File | New Project. In the left-hand menu click C++. Select the HelloSFML template and name your project Simple Game Engine.
- Now click OK.
- Right-click the HelloSFML.cpp file under the Source Files heading from the right-hand Solution Explorer window. Choose Rename and rename the file to Main. This is a more appropriate name as this will indeed be the source file containing the main function.
- Open Main.cpp by double-clicking it. Now delete all of its contents as we will be starting with an empty file.
- Copy & paste the SFML .dll files from the YOUR_DRIVE:\SFML\bin to YOUR_DRIVE:\Visual Studio Stuff\Projects\Simple Game Engine\Simple Game Engine. Obviously, if you configured your development environment slightly differently then your folder names will vary.
Now we can get coding. All the code is on the page and all the assets you need are made available from this page, but please take a look at the bonus download offer.
[sociallocker id=”14566″]
Thanks for the love! Here is the link to the simple-game-engine-c-bonus-download
[/sociallocker]
Also, note that all the bonus downloads for this and every future tutorial is available on an exclusive download area for my Patreon subscribers.
Planning the simple game engine
One of the problems that we had in the Pong game was how long and unwieldy the code was. If you consider that Pong is perhaps the simplest game it is possible to make then we need to think about improving the structure of our code. Object oriented programming in C++ allows us to break our code up into logical and manageable chunks called classes.
We will make a big improvement to the manageability of the code in this project compared to the Pong game with the introduction of an
Engine class. The Engine class will have three
private functions. They are
input,
update, and
draw. This should sound very familiar if you have done the Pong project. Each of these functions will hold a part of the code that was previously all in the
main function. Each of these functions will be in a code file of its own,
Input.cpp,
Update.cpp, and
Draw.cpp respectively.
There will also be one public function in the Engine class, which can be called with an instance of Engine which will be declared in Main.cpp. This function is appropriately called start and will be responsible for calling input, update, and draw, once for each frame of the game:
In addition, because we have abstracted the game loop to the Engine class, we can also move virtually all of the variables from main and make them members of Engine. All we need to do to get our game engine revving is create an instance of Engine and call its start function from main. Here is what the super-simple main function will look like when we are done. Don’t code it just yet, though.
int main() { // Declare an instance of Engine Engine engine; // Start the engine engine.start(); // Quit the game return 0; }
If you want to go way beyond this tutorial, please take a look at these three related books.
[widgets_on_pages id=”bcgp_cfgp_gpp”]
Now we can build the classes that we discussed.
Coding the Bob class
Bob is a simple class that will represent the player’s controllable character. It can only move left and right but when you see the code you will see that it would be trivial to extend this functionality. More significant, however, is that the Bob class can be easily copied and modified to become just about any type of game object you like. Simply apply the appropriate texture in the constructor, behaviour in the update function then declare, update and draw them in exactly the same way that we will soon see. If you want dozens, hundreds, or more of your new game object then just declare an entire array of them.
Bob.h
First, let’s code the header file of the Bob class.
Right-click Header Files in the Solution Explorer and select Add | New Item…. In the Add New Item window, highlight (by left-clicking) Header File (.h) and then in the Name field, type Bob.h. Finally, click the Add button. We are now ready to code the header file for the Bob class.
#pragma once #include <SFML/Graphics.hpp> using namespace sf; class Bob { // All the private variables can only be accessed internally private: // Where is Bob Vector2f m_Position; // Of course we will need a sprite Sprite m_Sprite; // And a texture // Bob has been working out and he is now a bit more muscular than before // Furthermore, he fancies himself in lumberjack attire Texture m_Texture; // Which direction(s) is the player currently moving in bool m_LeftPressed; bool m_RightPressed; // Bob's speed in pixels per second float m_Speed; // Public functions public: // We will set Bob up in the constructor Bob(); // Send a copy of the sprite to main Sprite getSprite(); // Move Bob in a specific direction void moveLeft(); void moveRight(); // Stop Bob moving in a specific direction void stopLeft(); void stopRight(); // We will call this function once every frame void update(float elapsedTime); };
In the previous code, we declare objects of type Texture and Sprite. You will see in the next code how we associate these with each other so that whenever we do anything with the Sprite it will be adorned by this rather handsome Bob character. Notice also the is a Vector2f called m_Position which can be manipulated and will be used to set Bob’s current position on the screen.
Right-click and select Save Image as… to download the previous image.
There are also two Boolean variables which will be set and unset in order to communicate with the update function which way Bob should be moving, if at all. There is also an int called m_Speed which will be assigned a value which determines how fast Bob will move.
The public section of the class has a getSprite function to return a copy of the Sprite object to the draw function where it is required in order to draw Bob to the screen. There are four setter functions moveLeft, moveRight, stopLeft, and stopRight. These functions will be called from the input function and are used to set the values of the two Booleans that control the movement.
The final function in the Bob.h file is the update function. You can see it takes a float variable. This function will be called each and every frame from the update function of the Engine class and will update Bob’s position by the right amount in the appropriate direction each frame.
Bob.cpp
Now we can code the definitions for all the functions we have just seen.
Right-click Source Files in the Solution Explorer and select Add | New Item…. In the Add New Item window, highlight (by left-clicking) C++ File (.cpp) and then in the Name field, type Bob.cpp. Finally, click the Add button. We are now ready to code the .cpp file for the Bob class.
#include "stdafx.h" #include "bob.h" Bob::Bob() { // How fast does Bob move? m_Speed = 400; // Associate a texture with the sprite m_Texture.loadFromFile("bob.png"); m_Sprite.setTexture(m_Texture); // Set the Bob's starting position m_Position.x = 500; m_Position.y = 800; } // Make the private spite available to the draw() function Sprite Bob::getSprite() { return m_Sprite; } void Bob::moveLeft() { m_LeftPressed = true; } void Bob::moveRight() { m_RightPressed = true; } void Bob::stopLeft() { m_LeftPressed = false; } void Bob::stopRight() { m_RightPressed = false; } // Move Bob based on the input this frame, // the time elapsed, and the speed void Bob::update(float elapsedTime) { if (m_RightPressed) { m_Position.x += m_Speed * elapsedTime; } if (m_LeftPressed) { m_Position.x -= m_Speed * elapsedTime; } // Now move the sprite to its new position m_Sprite.setPosition(m_Position); }
In the constructor function, Bob, above we set m_Speed to 400 which means Bob would cross a 1920 pixel screen width in around 5 seconds. We load the bob.png image into the Texture object and we associate it with the Sprite object. We also set the starting horizontal and vertical positions for Bob by initializing m_Position.x and m_Position.y. It is worth noting that depending on the resolution of your monitor you might want to adjust these values.
The getSprite function as expected returns a copy of m_Sprite. The four movement related functions play with our two Booleans. The ...Pressed functions set the appropriate Boolean to true and the stop... functions set the same to false. We can now see how all these ties together in the update function.
The update function starts with two if statements. The first checking whether m_RightPressed is true and the second detecting whether m_LeftPressed is true. Inside each of the if blocks m_Speed multiplied by elapsedTime is added or subtracted from m_Position.x. The elapsedTime variable is calculated and passed in by the start function of the Engine class. We will code that next.
As a final step for this class add bob.png to the Simple Game Engine/Simple Game Engine folder.
Coding the Engine class
The Engine class is what controls everything else. Once it is started in the main function which runs when the app runs it will hold control right up until the player quits the game. Let’s code it now, it is quite straightforward.
Engine.h
Right-click Header Files in the Solution Explorer and select Add | New Item…. In the Add New Item window, highlight (by left-clicking) Header File (.h) and then in the Name field, type Engine.h. Finally, click the Add button. We are now ready to code the header file for the Engine class. Add the following code.
#pragma once #include <SFML/Graphics.hpp> #include "Bob.h"; using namespace sf; class Engine { private: // A regular RenderWindow RenderWindow m_Window; // Declare a sprite and a Texture for the background Sprite m_BackgroundSprite; Texture m_BackgroundTexture; // An instance of Bob Bob m_Bob; // Private functions for internal use only void input(); void update(float dtAsSeconds); void draw(); public: // The Engine constructor Engine(); // start will call all the private functions void start(); };
Let’s talk about the variables first. There is an SFML RenderWIndow which is what we use to display everything. There is a Sprite and a Texture which will be used to draw a pretty background image. We declare an instance of the Bob class that we just finished coding a moment ago. There is also the three private functions, input, update, and draw. They are private because we don’t need or want to call them from outside of the Engine class.
Next, the code declares two public functions. The constructor called Engine will set the instance of the class up ready go and the start function is the function that will continuously call the input, update and draw functions, in that order, every frame.
Engine.cpp
In the Engine.cpp file, we will put the constructor ( Engine) and the public start function. All the rest of the functions will go in their own .cpp file, with a name that makes it clear what function goes where. This will not be a problem for the compiler as long as we add the appropriate include directive ( #include "Engine.h") at the top of all the files that contain function definitions from the Engine class.
Let’s get started by coding Engine and start in Engine.cpp. Right-click Source Files in the Solution Explorer and select Add | New Item…. In the Add New Item window, highlight (by left-clicking) C++ File (.cpp) and then in the Name field, type Engine.cpp. Finally, click the Add button. We are now ready to code the .cpp file for the Engine class.
#include "stdafx.h" #include "Engine.h" Engine::Engine() { // Get the screen resolution and create an SFML window and View Vector2f resolution; resolution.x = VideoMode::getDesktopMode().width; resolution.y = VideoMode::getDesktopMode().height; m_Window.create(VideoMode(resolution.x, resolution.y), "Simple Game Engine", Style::Fullscreen); // Load the background into the texture // Be sure to scale this image to your screen size m_BackgroundTexture.loadFromFile("background.jpg"); // Associate the sprite with the texture m_BackgroundSprite.setTexture(m_BackgroundTexture); } void Engine::start() { // Timing Clock clock; while (m_Window.isOpen()) { // Restart the clock and save the elapsed time into dt Time dt = clock.restart(); // Make a fraction from the delta time float dtAsSeconds = dt.asSeconds(); input(); update(dtAsSeconds); draw(); } }
The constructor function gets the screen resolution and then opens a fullscreen window with m_Window.create. Finally, in the constructor, we load the image into the Texture and associate it with the Sprite.
You need to add an image for the background. Here is a great place to get lots of images with varying sizes.
http://www.spyderonlines.com/wallpapers/game-background-images.html
Use an image editor like GIMP or Photoshop to scale the background to the same resolution as your screen. Rename the image as background.jpg. Add the backgroung.jpg image to the Simple Game Engine/Simple Game Engine folder.
The other function in the code above is the start function. This function contains just a continuous while loop that will only break when the window ( m_Window) is closed. We will give the player the ability to do this in the input function soon.
The start function then calculates how long the previous frame took, stores the answer as a float called dtAsSeconds then calls input, update and draw. Notice that dtAsSeconds get passed to update that will require the value because it will be calling the update function of the Bob instance.
I hope you agree that is extremely simple. It is arguably easier than have to handle the sprawl of code that we did in the Pong game.
Coding the three stages of the game loop
[widgets_on_pages id=”udemy_advert_cpp_2″][widgets_on_pages id=”udemy_code_details”]
The next three functions will be coded in their own individual files but don’t forget that they are part of the
Engine class and were declared in the
Engine.h file. At the top of each file, we will add the directive
#include "Engine.h" so that Visual Studio knows what we are doing.
Handling player input
The first of these functions we will code is input.
Right-click Source Files in the Solution Explorer and select Add | New Item…. In the Add New Item window, highlight (by left-clicking) C++ File (.cpp) and then in the Name field, type Input.cpp. Finally, click the Add button. Here is the code for Input.cpp.
#include "stdafx.h" #include "Engine.h" void Engine::input() { // Handle the player quitting if (Keyboard::isKeyPressed(Keyboard::Escape)) { m_Window.close(); } // Handle the player moving if (Keyboard::isKeyPressed(Keyboard::A)) { m_Bob.moveLeft(); } else { m_Bob.stopLeft(); } if (Keyboard::isKeyPressed(Keyboard::D)) { m_Bob.moveRight(); } else { m_Bob.stopRight(); } }
In the input function, we use the SFML Keyboard::isKeyPressed constants to verify which keyboard keys are currently pressed. If the Escape key is pressed m_Window is closed. This has the effect of breaking out of the while loop in the start function. This causes execution to go back to the main function and the game will close.
If the A or D keys are pressed we call the appropriate move... function on our Bob instance. Notice that when the A or D keys are not pressed the two else clauses call the corresponding stop... functions. This is the final piece of the puzzle that enables the player to move Bob left and right.
Updating the game objects
Next, we come to the super-simple update function. Any new objects you create should have their own update functions called from here. You should also add collision detection to the end of this function.
Right-click Source Files in the Solution Explorer and select Add | New Item…. In the Add New Item window, highlight (by left-clicking) C++ File (.cpp) and then in the Name field, type Update.cpp. Finally, click the Add button. Here is the code for Update.cpp.
#include "stdafx.h" #include "Engine.h" using namespace sf; void Engine::update(float dtAsSeconds) { m_Bob.update(dtAsSeconds); }
As we only have one game object we call m_Bob.update and pass in dtAsSeconds and then we are finished with this function.
Drawing the scene
This is the final function of the Engine class.
Right-click Source Files in the Solution Explorer and select Add | New Item…. In the Add New Item window, highlight (by left-clicking) C++ File (.cpp) and then in the Name field, type Draw.cpp. Finally, click the Add button. Here is the code for Draw.cpp.
#include "stdafx.h" #include "Engine.h" void Engine::draw() { // Rub out the last frame m_Window.clear(Color::White); // Draw the background m_Window.draw(m_BackgroundSprite); m_Window.draw(m_Bob.getSprite()); // Show everything we have just drawn m_Window.display(); }
In the draw function, there is nothing that we didn’t see in the Pong game. First, we clear the screen with the clear function. Next, we draw the background followed by Bob. The things to note here are that we must draw the background first so Bob is drawn on top and that when we draw Bob we call the getSprite function which gets a copy of the Sprite in the Bob class.
Getting the engine started with Main
This is the shortest main function out of all the C++ tutorials on this site.
Add the code we have already glimpsed at to Main.cpp. Here it is again in its entirety.
#include "stdafx.h" #include "Engine.h" int main() { // Declare an instance of Engine Engine engine; // Start the engine engine.start(); // Quit in the usual way when the engine is stopped return 0; }
First, we declare an instance of Engine, call the start function and execution will move to the Engine class until the player quits by pressing the Escape key.
You can now run the game and move Bob left and right with the A and D keyboard keys.
Conclusion, flaws & what next?
When you added the background and the player we had to adjust the code to suit your specific resolution. This is obviously not suitable for a game you want to release on Steam. It is quite easy to fix this flaw using the SFML View class. I didn’t add this feature because at some point I had to stop adding features. The View class uses OpenGL to make independent drawing layers and can be used to make some really cool effects like split-screen gameplay, mini maps, and levels that can rotate and zoom. I will publish a whole working game that uses these features soon.
Another obvious flaw that you probably spotted was that the game engine doesn’t handle for different game states like paused, home screen and playing. You can quickly cater for this by creating some Booleans to represent each state. Perhaps isPlaying, isPaused etc. This isn’t the best way of doing it but as I said before I had to draw the line at the features to include in what should be a simple tutorial. We will see a neater and more efficient way to handle states in a forthcoming full-game project, most likely a platformer.
In addition, any game you are going to release to the world will have more features like sound, music, artificial intelligence, saving of high scores and more besides. Most of these features can be bolted onto this engine. It is true, unfortunately, that eventually you will end up with code sprawl again but the purpose of the tutorial is meant to be instructional as well as practical and when we dive into something more complicated this engine should serve as good preparation and starting point.
I hope you had some fun with this simple C++ game engine. Please ask questions and leave comments if you would like to.
In case anyone is wondering the clock variable was formatted in pink automatically!?
Hi John,
Great to see a new addition to the C++/SFML tutorials. I’m really enjoying these and learning a lot from them. Thank you. Can’t wait to get my hands on your upcoming book!
Keep up the good work!!
Thanks for the message Dave. Book is imminent now. Watch announcements here and on Facebook for a few free review copies.
Hey John, the tutorial was nice and easy to follow. I also implemented the collision property. Now I am eager to know that when are you releasing more tutorials on this? And as I have completed this tutorial, what should I do next?
I want to make a more realistic game. Is this possible with SFML and when are you uploading a full-game project.
Cant wait for that
You can do allot with SFML. Virtually anything you can imagine in 2D. I thought long before choosing SFML for the C++ tutorials. At this stage I would suggest you pick a simple game and go ahead and make it. If you want ideas there are a number of SFML books on Amazon but they are of varying difficulty and contents so check the contents carefully before buying.
My next tutorials for C++ and SFML will likely be out in the next month and hopefully one more (more advanced) full game (that uses this engine) by the end of the year.
Thanks for your message.
could you share your code for the collision detection?
Hi Michael,
Take a look at the C++ Pong project for some simple collision with SFML and C++. There will be one more full game project for SFML before the end of the year. This project will use this simple game engine and also incorporate collision detection.
Alright. Thank you so much for guiding me through
What do you recomend me doing after completing all the SFML Projects and C++ tutorials?
If you have decided that PC gaming is for you then you could find some toughe (and more rewarding) SFML projects. There are numerous books on Amazon but just be careful to check the contents to make sure they are right for you. You could also study the SFML docs which woll reveal more features. If you want to branch out a bit why not try a different engine/api. These Unity tutorials use C# which will probabaly seem fammiliar coming from C++.
Hope this helps a bit.
Yea I´ve decided to code for PC and I want to do projects in SFML. Can you recommend a specific book that would be good after this?
It depends on your level of C++ knowledge which would be best. Look into one of these.
Very little knowledge:http://gamecodeschool.com/blog/beginning-c-plus-plus-game-programming/
Good beginner knowledge: http://gamecodeschool.com/blog/review-of-sfml-blueprints/
Intermediate knowledge: https://www.packtpub.com/game-development/sfml-game-development or https://www.packtpub.com/game-development/sfml-game-development-example
Also, go and read the docs and tutorials on the SFML site: http://www.sfml-dev.org/tutorials/2.4/
Hope this helps a bit and check back soon for some more SFML tutorials here.
Disclaimer(the beginner book is my own)
Thank you so much for recommending!
I will probabaly look up all of these and I will come back to do the upcoming tutorials!
man, the game window is just white for me.
i copied all the code, so what the heck is wrong
‘SimpleGameEngine.exe’ (Win32): Loaded ‘D:\Programme (x86)\Visual Studio Stuff\Projects\SimpleGameEngine\Debug\SimpleGameEngine.exe’. Symbols loaded.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\ntdll.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\kernel32.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\KernelBase.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘D:\Programme (x86)\Visual Studio Stuff\Projects\SimpleGameEngine\sfml-graphics-d-2.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘D:\Programme (x86)\Visual Studio Stuff\Projects\SimpleGameEngine\sfml-window-d-2.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘D:\Programme (x86)\Visual Studio Stuff\Projects\SimpleGameEngine\sfml-system-d-2.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\winmm.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\msvcrt.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\user32.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\gdi32.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\lpk.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\usp10.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\advapi32.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\sechost.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\rpcrt4.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\sspicli.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\cryptbase.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\msvcp140d.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\vcruntime140d.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\ucrtbased.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\api-ms-win-core-timezone-l1-1-0.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\api-ms-win-core-file-l2-1-0.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\api-ms-win-core-localization-l1-2-0.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\api-ms-win-core-synch-l1-2-0.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\api-ms-win-core-processthreads-l1-1-1.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\api-ms-win-core-file-l1-2-0.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\opengl32.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\glu32.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\ddraw.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\dciman32.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\setupapi.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\cfgmgr32.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\oleaut32.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\ole32.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\devobj.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\dwmapi.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\imm32.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\msctf.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\uxtheme.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\nvoglv32.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\shell32.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\shlwapi.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\wtsapi32.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\version.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\dbghelp.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\advapi32.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Unloaded ‘C:\Windows\SysWOW64\advapi32.dll’
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\gdi32.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Unloaded ‘C:\Windows\SysWOW64\gdi32.dll’
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\wintrust.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\crypt32.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\msasn1.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\ntmarta.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\Wldap32.dll’. Cannot find or open the PDB file.
The thread 0x818 has exited with code 0 (0x0).
The thread 0x1f94 has exited with code 0 (0x0).
The thread 0x1978 has exited with code 0 (0x0).
The thread 0x1f8c has exited with code 0 (0x0).
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\powrprof.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Unloaded ‘C:\Windows\SysWOW64\powrprof.dll’
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\winsta.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\dinput.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\hid.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Loaded ‘C:\Windows\SysWOW64\ole32.dll’. Cannot find or open the PDB file.
‘SimpleGameEngine.exe’ (Win32): Unloaded ‘C:\Windows\SysWOW64\ole32.dll’
dont know why i get all this when i just cannot load bob and the background
Most likley the problem is setup/configuration. See my previous 2 tips.
Are the SFML.dll in the project folder. If you have trouble get the helo world project working first.
what will happen if I do not get the sfml? does it matter
SFML is an essential part. This is what SFML actually is.
Can you make a tutorial with all these features implemented: Engine, Collision Detection, Score, Lives, etc.
Hi Mike,
Thanks for commenting. There will be some new tutorials soon. Probably February,probably a platform game with AI state machines, shooting and collisions.
Hello,
The game engine works fine if you compile it in Debug, but the Release version is just a white background. It also says various libraries can’t be loaded in the debug info.
Did you follow my setting up SFML tutorial? If so, reconfigure (probably start a new) project to include the .dll files that don’t end in -d. Then the Release build should work. Hope this helps.
thanks,
how would i do that? is there a way to specify that it doesn’t include those, or would i have to just do it manually?
Hi Jack,
Follow this article http://gamecodeschool.com/sfml/building-your-first-sfml-game-project/. When you link to and add the .dll files. Change the text and the actual files as well to use the ones that don’t end in -d. The -d stands for debug and can’t be linked into a release build. Hope this helps, John
I was getting the white too, but the solution seemed to be to put the full path for the images. Then when I ran the executable outside of Visual Studio it worked fine.
Hey John,
Going through your tutorials have been awesome for me. I am having the same problem as Andreas where the screen just shows white, and the Output states that it can’t load the .dlls. I did as you recommended to Andreas and made sure that all my configurations are right. I have been able to successfully run all the other projects with the same setup, so I’m not sure what would be different. Hope you have an idea.
I did some more playing around with it, and found that if I switch the style of the window to Default instead of Fullscreen, I cannot do anything to the window. The only way I can close it is to press the Escape key. I can’t move the window around, it’s as though the program locks up.
Hi Bradey, yes the type of Window has various consequences. Take a look at this article for a good overview. https://www.sfml-dev.org/tutorials/2.0/window-window.php
Hi Bradey. That’s odd that the others work using the same configuration. Is it possible that just one of the .dll is missing. Alternatively, try copying/overwriting the code from this project into one of the projects which is working.
Say I wanted to make a 2d fighting game, I want to adjust this to see how making one would work, how would I make it so that when it moves to left/right it changes the Sprite so it looks different, where to put it also and, if you have time, how would you make something like a attack for example if I right clicked it does a dash forward
First, you need to assign a key to trigger the event, then change the image to represent the attack http://gamecodeschool.com/android/coding-android-sprite-sheet-animations/ then play a sound effect etc. Of course, you then want to detect collisions. C++ video course covering all this and more coming end of May 2017. Sorry for delay.
without trying to be toch of a pain, how do i; put in an animation for him walking; make it so when he gets to the end it sets up another page and finally could you advise me of a website to do these animations?
You need to flip between different frames of animation. Here is an example in Java/Android that wouldn’t need too much modification to work with C++/SFML. http://gamecodeschool.com/android/coding-android-sprite-sheet-animations/
mines says it cant include #include “stdafx.h” I don’t understand why…
Try removing the line?
Its not working! I am using xcode! when I run the project the window never open and theres no error! So i have no idea whats the problem
This is difficult for me to solve as I have never used XCode. It seems odd that absolutely nothing happens. There must be some output from the IDE somewhere; like an eror of some sort?
Did the next full game project in SFML ever get made? Where can I find it?
Sorry, no. Google decided to stop sending many visitors shortly after this was posted and there didn’t seem much point. Sorry about that.
Thats a bummer John I really enjoyed doing this even knowing little about coding everything worked great and I’m currently fiddling with the inputs trying to get Bob to move up and down, I also have to commend you on your website, assuming you did it yourself, it is fantastic and everything I want mine to be I hope you may one day come back to SFML and make some more Great tutorials
-West
Thanks. I hope it will be possible some time.
Hey John – Even though you stopped adding content here, I wanted to say I’ve found your tutorials to be excellent!
—
To anyone else who comes here looking to begin learning about game development with SFML – if you’re having trouble getting the code for this tutorial to produce any results, it seems like SFML requires the following block of code to be added in the game loop:
sf::Event event; // if you’re “using namespace sf” just get rid of “sf::”
while (mWindow.pollEvent(event))
{
if (event.type == sf::Event::Closed) // if you’re “using namespace sf” just get rid of “sf::”
mWindow.close();
}
Without it, the output binary runs, but no window seems to get rendered. I added mine just after after opening of the “while (mWindow.isOpen() ) {” loop, inside Engine::start()
Thanks for your comment. I will leave your advice here for future readers.
yo your comment saved me bro. without that chunk of code my window renders but becomes unresponsive instantly. good catch!
Hi,
Basically, The Engine seems simple but if I may ask why does the engine has the bob class in it. Assuming a person using this engine does want to use bob rather he want a car to exist. I feel that they should be at least a class that hold’s a character data.
My Question is huge engines like Unity and Unreal, Do they have different engine’s for RPG, SPORTS, SIMULATION etc.
Not really different versions of engine but different tools suitable for different projects. Also the asset stores have loads of free/cheap templates for quick start.
Hi John,
Your tutorials were so helpful. Thanks a lot! And i want to you if you can help me to make the character jumping in the game engine. Thanks!
You need to create some boolean states. Like isJuming, isFalling, and then code up and down motion in the update method depending upon the current state. You will also need to change between the states using a timer. Sfml has a clock class for this.
awesome bro