Ankur Mallick
Ankur Mallick

Reputation: 33

How you use deltatime in raylib?

Can anyone please confirm if this is how you use deltatime in raylib using GetFrameTime(). If not, then how exactly?

#include <raylib.h>

int main(void)
{
    InitWindow(800, 450, "sample");

    Rectangle rec = {100, 100, 50, 50};

    SetTargetFPS(60);
    while (!WindowShouldClose())
    {
        float dt = GetFrameTime()*GetFPS();

        if(IsKeyDown(KEY_RIGHT))
            rec.x += 5*dt;

        BeginDrawing();
            ClearBackground(BLACK);
            DrawRectangleRec(rec, RED);
        EndDrawing();
    }
    CloseWindow();

    return 0;
}

This is the code which I tried.

Upvotes: 0

Views: 785

Answers (1)

CrazyVince
CrazyVince

Reputation: 1

you dont need to multiply the GetFrameTime() result with the GetFps() result, because the GetFrameTime() function returns the delta time.

Upvotes: 0

Related Questions