Frax is a lightweight, header-only 2D game framework built on top of raylib. It’s designed to give you a more structured, easier, and customizable way to build games without the usual boilerplate.
- Header-only → just drop in and use
- Zero dependencies (only raylib required)
- Easy-to-use API for scenes, sprites, and rectangles
- Automatic sprite & texture management
- Simple rectangle manipulation utilities
- Highly customizable
- Network management
- Audio management
The recommended way to add Frax to your project:
git submodule add https://github.com/mastercuber55/Frax-Framework.git external/FraxFrameworkIn your main file (e.g. main.cxx), define FRAX_IML before including the header:
#define FRAX_IML
#include "Frax.hpp"FRAX_SCENE_DEFAULT_BACKGROUND_COLOR→ Default isBLACK
Everything is contained in a single header (Frax.hpp). The code is straightforward, and the top section of the file explains most things.
(ProjectName)
├── Assets
│ ├── Board.gif
│ └── Marks.png
├── CMakeLists.txt
├── external
│ └── FraxFramework
│ └── Frax.hpp
├── main.cxx
└── Scenes
├── SceneTitle.cxx
├── SceneGame.cxx
└── Scenes.hpp
Header (Scenes/Scenes.hpp):
struct SceneGame : Frax::Scene {
Sound shoot;
Camera2D Cam;
Frax::Rect Player;
SceneGame();
void Update(float dt) override;
void Draw() override;
~SceneGame();
};Implementation (Scenes/SceneGame.cxx):
#include "Scenes.hpp"
SceneGame::SceneGame() : Player({0, 0, 32, 32}, "Assets/Player.png") {
// Initialize game resources
}
void SceneGame::Update(float dt) {
// Handle input, logic, events
}
void SceneGame::Draw() {
// Pre-camera layer (backgrounds, etc.)
BeginMode2D(Cam);
Player.Draw();
EndMode2D();
// Post-camera layer (UI, overlays, etc.)
}
SceneGame::~SceneGame() {
// Cleanup if needed
}Managing textures, positions, sizes, and rotations manually can get messy. Frax provides Rect for a simple, ready-to-use sprite entity:
struct Rect {
// Variables
float x, y, w, h;
double Rotation;
std::shared_ptr<Texture> TexturePtr;
Rectangle Source;
Color Tint;
std::any Data;
// Constructors
Rect(float x, float y, float w, float h, Color tint = WHITE);
Rect(Rectangle dest, Color tint = WHITE);
Rect(Rectangle dest, const std::string &textureFileStr,
Rectangle Source = {0, 0, -1, -1});
~Rect();
// Setters
void SetCenter(Vector2 cenpos);
void operator=(Vector2 pos);
void SetTextureFile(const std::string &textureFileStr);
// Getters
Vector2 GetCenter();
operator Vector2() const;
operator Rectangle() const;
// Utilities
void Draw();
};- All fields are public for easy direct access.
TexturePtris automatically managed by Frax’s internal sprite manager.Dataallows you to attach arbitrary data (e.g., a physics body).
For more complex entities, inherit Rect and add your own variables:
struct Entity : Frax::Rect {
float Health;
Pebble::Obj* Phy;
using Rect::Rect; // inherit all constructors
void Draw(); // Syncs the Virtual Body and Physical Body's positions and orientation before actually drawing.
};Here, we attach a physics body (via Pebble) and a health variable.
📝 Tip: Use
using Rect::Rectto inherit constructors. Define custom constructors if needed.
- Chipmunk Physics
- Pebble (wrapper for Chipmunk)
- Box2D