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

Author Topic: 2D Game Engine Made Using SFML 2.1 - Open Source  (Read 4275 times)

0 Members and 1 Guest are viewing this topic.


  • Newbie
  • *
  • Posts: 11
    • View Profile
2D Game Engine Made Using SFML 2.1 - Open Source
« on: June 03, 2017, 01:04:27 am »

I created a 2D Game engine. Most of the documentation is in Portuguese, but the methods names and demos are written in English. If there is enough interest in the engine I will translate it to English. It is open source, here is a video of the demo, using open source assets and some songs from a past game that I started to develop.
The engine contains:
- Character management
- Multiple map layer
- Layers to set: Items, Objects, Collision.
- Positional Sound.
- Dialog management, where you can set options to trigger other dialogs. Also you can set callbacks for each options, creating some kind of tree.
- Sprite management.
- Text/Font management.
- Background Music.
- Level transition.
And others

Notice that most of those features are already present on SFML, like positional sound. The Engine provides a way to load those from files (each map layer (item, object, collision, sound) can be loaded from files).

This project was my final computer science graduation project. Also I wrote an article about it, you can find it here: http://www.sbgames.org/sbgames2015/anaispdf/computacao-short/147421.pdf, on engine implementation you can find the modules.

The code is open source, feel free to modify, improve or change it... if you want. This project is somehow old to me, from 2014. But I saw so many nice SFML projects on the SFML twitter that I imagined that this old project can maybe help someone.

The engine was made to develop zelda style games (action adventure), but can be extended.

Here is a demo of the Engine: https://www.youtube.com/watch?v=7YTccI8_ZTs.
The quality is not great (Should have kept the original one).

This code was tested on windows and mac os x with SFML 2.1. There are some hacks to make it work on previous versions of Visual Studio, like default parameters for a variadic template argument.

You can find the code here: https://github.com/AAGEngine

Hope you guys like :)

NOTE: As it was pointed out, the Engine can have several improvements. I agree with most of them, maybe all of them :). But because it was my first experience with C++11 and it was a graduation project there are several places that the Engine can improve. The main reason why the engine stayed like that was the fact that I was never able to start working on a game, the main reason being that I am horrible at pixel art. If I have free time I will fix several things that were pointed out, probably most of them... But if someone wants to use the engine in total or parts of that, feel free to do so.
« Last Edit: June 04, 2017, 05:44:27 pm by lefsler »


  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: 2D Game Engine Made Using SFML 2.1 - Open Source
« Reply #1 on: June 03, 2017, 01:07:47 pm »

in my opinion, you are using too many maps, expecially in your input manager. It kills performance. I suggest you to use array (normal or std::array) or std::vector for that and use input code (i mean e.g. sf::Keyboard::A, event.key.code) as an array index. It gives you guaranteed O(1) time look-up.

Gold rule "Always pass objects by const reference". In many functions (in all of them i think) you are sending std::string by value. Performance killed again. Send it by (const) reference or by value and std::move from them. It concerns all non-primitive things.

A lot of static variables, which means they are not within class they belong to. Possible cache misses.

Using 1-dimensional array to represent 2 dimenions? Good one ;)
imageValue = tileData[(blockPosition.y*tileHeader->tileBlock.x)+blockPosition.x];

As you are coding in C++11, consider using smart pointers and move semantics.

In some constructors you are missing member initializer lists.

Is there a reason to use FILE and fread instead of std::fstream and malloc instead of new?

Keep coding and good luck :)


  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: 2D Game Engine Made Using SFML 2.1 - Open Source
« Reply #2 on: June 03, 2017, 02:03:23 pm »

I totally agree with you on the keyboard and const reference, especially const reference. Even if the github says 10 months, this code is older than that, 10-11 months ago was when I decided to create a public repository for the project. At that time I was not worried about const reference, which now I totally am right now. But because I never used the engine again I never revisited this code.

For the static variables, as far as I remember those are implemented like that because I wanted to allow access to some functionalities without the need to instantiate that, I will try to revisit this code with another eyes.

As in the proposal of the final project I put to many items I had to implement those like I specified.
There is another point where I want to improve performance, which is the pathfind, as it manages objects with different sizes, but the initialization process of the vector is poorly implemented. Because I calculate for each tile how many tiles around it are free, so if this tile have 4 free neighbors this means that I can pass an element 4 times bigger then it on that tile (or node as it becomes later), the process to analise the neighbors are not well implemented.

Also agreed that I should use fstream, and initializers list (which for the time when I implemented this project it was an experience to use c++11, so a lot of move, initializer list, smart pointers and other nice features were left behind).

Thanks for the feedback :)