Simple Example


This example will show you how to write a simple application that display a rotating outline square in the middle of the screen, It's important to mention that every Playground2D Application starts by creating a world. The world accepts layers or how I named them "Scenes", The world creates a window for you in which you provide a struct that contains the properties of the window (width, height etc...).


            #define PLAYGROUND_2D

            #include <Playground2D.h>
            #include <glm/glm.hpp>

            using namespace pg2D;

            class RotatingSquare : public Scene {
            public:
                RotatingSquare(const std::string& sceneName) : Scene(sceneName) {}
                ~RotatingSquare() {}

                virtual void OnStart() override {
                    m_Camera = Camera2D(ownerWorld->GetWindow());
                }

                float angle = 0.0f;
                virtual void OnUpdate() override {
                    m_Camera.Update();

                    angle += m_DeltaTime.GetMilliseconds() / 4;
                }

                virtual void OnDraw() override {
                    static RGBA8 color = { 255, 255, 255, 255 };
                    m_ShapeBatch.DrawBox(glm::vec2(0.0f), glm::vec2(32.0f), color, angle);

                    m_ShapeBatch.Render(m_Camera, 1.0f);
                }

                virtual void OnEvent(Event& e) override {

                }

            private:
                Camera2D m_Camera;

                ShapeBatch m_ShapeBatch;
            };

            int main() {
                WindowProperties windowProps = { 1366, 768, "Rotating Square", WindowConfigurations::UNRESIZABLE };
                World world(windowProps);

                world.GetScenesList()->RegisterScene(new RotatingSquare("Rotating Square"));
                world.AddScene("Rotating Square");

                world.Run();
                return 0;
            }
        

Results

Rotating Square Result

Steps

Installation Documentation