// Initialize the windowInitWindow(screenWidth,screenHeight,"Window Title");// Set the target FPSSetTargetFPS(60);// Close the window and clean up resourcesCloseWindow();
Basic Structure
Main Game Loop
while(!WindowShouldClose())// Detect window close button or ESC key{// Update game state// Draw everythingBeginDrawing();ClearBackground(RAYWHITE);// Drawing code goes hereEndDrawing();}
Drawing Shapes
Drawing a Rectangle
DrawRectangle(x,y,width,height,color);
Drawing a Circle
DrawCircle(x,y,radius,color);
Drawing a Line
DrawLine(startX,startY,endX,endY,color);
Handling Input
Keyboard Input
if(IsKeyDown(KEY_RIGHT)){// Right arrow key is being held down}if(IsKeyPressed(KEY_SPACE)){// Space key was just pressed}
Mouse Input
Vector2mousePosition=GetMousePosition();if(IsMouseButtonDown(MOUSE_LEFT_BUTTON)){// Left mouse button is being held down}
#include"raylib.h"intmain(void){// InitializationconstintscreenWidth=800;constintscreenHeight=450;InitWindow(screenWidth,screenHeight,"raylib [core] example - basic window");SetTargetFPS(60);// Main game loopwhile(!WindowShouldClose()){// Update// DrawBeginDrawing();ClearBackground(RAYWHITE);DrawText("Congrats! You created your first window!",190,200,20,LIGHTGRAY);EndDrawing();}// De-InitializationCloseWindow();return0;}