DEV Community

MiguelMJ
MiguelMJ

Posted on

5

Making a level editor with SFML (C++) - Part 1

A level editor is something that I've wanted to do for a long time in SFML, but has always been delayed. Fortunately, my last project (Candle, a library for 2D lighting), made me dive entirely into SFML again, so when I finished it, the natural thing was to start with the editor project right ahead.

The design

The GUI

There are several libraries to make GUIs in SFML. However, I didn't want to use any of them, for two reasons: first, I wanted to learn to make GUIs from scratch in order to know how to implement one in my future game; second, I may suffer a little bit of NIH syndrome.

Anyways, the GUI I require is intended for my personal use and not very complex. The required features are:

  • Pannable views with resizable viewports.
  • A basic clickable menu.
  • A color picker.
  • Modularity centered around tools, so that it is easy to add new ones and scale the already implemented.

The levels

The editor will be focused on a tile world (or grid world). The levels I want to make would have the following components (note: I will be using the words component and entity, but not in terms of the ECS architecture):

  • Visual component. It will be divided in layers (maybe with parallax) and it would require tools to:
    • Set and transform the texture of a cell.
    • Set the color of a cell.
    • Set and transform visual elements that are not fixed to the grid.
    • Set and transform light sources and lighting areas (here I will use Candle).
  • Collisions component. It will require a tool to set the type of each cell, where the type can be:
    • Solid cells.
    • Unsolid cells.
    • Cells with a solid slope.
  • Dynamic components. These will be the entities within the level that do not belong to the grid, that will have the following elements:
    • A sprite, optionally animated.
    • A collision rectangle, circle or capsule.
    • Some basic physic properties, as velocity and bounciness.
  • Lastly, I would like to make the levels scriptable. I will be embedding Lua in the editor, so I can test directly the scripts there.

Serialization

Obviously, any editor would be useless if you couldn't save you work. I will use cereal to serialize the levels and the custom assets.


What is your experience with SFML? Have you got any project that you want to share? Feel free to leave a comment with any library that would be useful for other people using SFML!

Image of Quadratic

AI, code, and data connections in a familiar spreadsheet UI

Simplify data analysis by connecting directly to your database or API, writing code, and using the latest LLMs.

Try Quadratic free

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay