sunlight is an open source library written in C++ to make 2D games. Overall, its present main features include a manager that can deal with map, collision, sprites and graphic primitives.
raylib was used for graphic backend, but the project aims to be extended to SDL and many others. Rendering is exposed through an IEngine interface (src/engines/) so a new backend only needs its own implementation plus one line in the engine factory, without touching the rest of the codebase.
- API documentation 📖
- Changelog 📜
- License (zlib) 📄
- Requirements
- HowTo
- Samples
In order to make sunlight run as desired, it is necessary to install the dependencies listed below beforehand:
You may install the package on its official page. Higher versions are also supported.
-
For Linux
Ubuntu/Debian users can install the package by using the command
apt-geton their Linux shell.It is also recommended to install by using the standard package manager offered by your prefered distro.
-
For MacOS
Mac users may obtain the package through MacPorts or Homebrew.
Use vcpkg to integrate C/C++ libraries using Visual Studio.
By default, the project's CMakeLists will automatically search LibXML and its dependencies (LibIconv). For those who might want to use the library installed on your system, the following parameter should be used to call CMake:
cmake -DUSE_LOCAL_LIBXML2zlib can be installed by using your standard package manager.
The installation steps for which OS are listed below.
- Ubuntu/Debian family
apt-get install zlib1g-dev- Windows (vcpkg)
.\vcpkg\vcpkg install zlib:x64-windowsPhysFS backs sunlight's virtual filesystem (mounting a loose directory or an archive so every resource read — textures, sound, tilemaps — goes through one path space). Like LibXML2/tmx/raylib, it is fetched and built automatically via FetchContent; no separate install is required.
You may find the detailed instructions by clicking here and following the steps regarding the operational system you're using.
By default, sunlight doesn't build the projects' samples.
In order to make it compile with samples, it is necessary to open the CMakeLists on the project's root to change the option from OFF to ON, as shown below:
option(BUILD_LIBRARY_SAMPLES "Build SunLight library samples" ON)Note
You may also use the following command line on your system's shell:
cmake -DBUILD_LIBRARY_SAMPLES=ONUnit tests are also opt-in, using doctest fetched automatically via CMake:
cmake -DBUILD_LIBRARY_TESTS=ON
cmake --build build --target sunlight_tests
./build/tests/sunlight_testsNote
You may also run the tests through CTest:
ctest --test-dir buildIf you intend to use VsCode as your IDE, follow the instructions shown here.
Each sample takes its own directory as argv[1] and resolves its resources relative to it, e.g.:
./build/samples/sprite/sprite_test samples/sprite/- tilemaprenderer — the minimal setup: loads a Tiled map and drives the renderer's camera/zoom, no sprites.
- sprite — builds on
tilemaprendererby adding an animatedSpriteon top of the map. - collision — builds on
spriteby making the sprite player-controlled and colliding it with a static obstacle viaCollisionManager. - gamepad — builds on
collisionby giving two independent characters their own controller: one gamepad's left stick/DPad drives Sunny, the right stick/face buttons drive a second sprite. - scriptprocessor — a scripted "stage intro" cutscene demonstrating
ScriptProcessor: queued commands load a stage, slide sprites on screen, and play/pause/resume a tone viaSoundManager, exercising every control-flow command (WAIT_CMD,WAIT_SPRITES_QUEUE_EMPTY,LOOP_CMD/END_LOOP_CMD,LABEL_CMD/GOTO_LABEL_CMD). - multiview — the same map and the same character shown in three places at once (a main view, a minimap, and a zoomed close-up that follows the character), demonstrating
sunlight's multiple views (TileMapRenderer::CreateView) and world-space sprites (Sprite::SetWorldSpace).