How to use raylib - 10 common examples

To help you get started, we’ve selected a few raylib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RobLoach / node-raylib / examples / textures / textures_image_loading.js View on Github external
while (!r.WindowShouldClose())    // Detect window close button or ESC key
{
    // Update
    //----------------------------------------------------------------------------------
    // TODO: Update your variables here
    //----------------------------------------------------------------------------------
console.log('5')
    // Draw
    //----------------------------------------------------------------------------------
    r.BeginDrawing();

        r.ClearBackground(r.RAYWHITE);

        r.DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, r.WHITE);

        r.DrawText("this IS a texture loaded from an image!", 300, 370, 10, r.GRAY);

    r.EndDrawing();
    //----------------------------------------------------------------------------------
}

// De-Initialization
//--------------------------------------------------------------------------------------
r.UnloadTexture(texture);       // Texture unloading

r.CloseWindow();                // Close window and OpenGL context
//--------------------------------------------------------------------------------------
github RobLoach / node-raylib / examples / textures / textures_image_loading.js View on Github external
const texture = r.LoadTextureFromImage(image);          // Image converted to texture, GPU memory (VRAM)

r.UnloadImage(image);   // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
//---------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose())    // Detect window close button or ESC key
{
    // Update
    //----------------------------------------------------------------------------------
    // TODO: Update your variables here
    //----------------------------------------------------------------------------------
console.log('5')
    // Draw
    //----------------------------------------------------------------------------------
    r.BeginDrawing();

        r.ClearBackground(r.RAYWHITE);

        r.DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, r.WHITE);

        r.DrawText("this IS a texture loaded from an image!", 300, 370, 10, r.GRAY);

    r.EndDrawing();
    //----------------------------------------------------------------------------------
}

// De-Initialization
//--------------------------------------------------------------------------------------
r.UnloadTexture(texture);       // Texture unloading

r.CloseWindow();                // Close window and OpenGL context
github taniarascia / chip8 / example.js View on Github external
r.InitWindow(screenWidth, screenHeight, 'raylib [shapes] example - basic shapes drawing')

r.SetTargetFPS(60)
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose()) {
  // Detect window close button or ESC key
  // Update
  //----------------------------------------------------------------------------------
  // TODO: Update your variables here
  //----------------------------------------------------------------------------------

  // Draw
  //----------------------------------------------------------------------------------
  r.BeginDrawing()

  r.ClearBackground(r.RAYWHITE)

  console.log('hello')

  r.GetKeyPressed()
  console.log(r.IsKeyDown(r.KEY_ONE))

  // console.log(r.GetKeyPressed())
  r.DrawText('some basic shapes available on raylib', 20, 20, 20, r.DARKGRAY)

  var position = {
    x: 100,
    y: 100,
  }
  var size = {
github taniarascia / chip8 / example.js View on Github external
r.SetTargetFPS(60)
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose()) {
  // Detect window close button or ESC key
  // Update
  //----------------------------------------------------------------------------------
  // TODO: Update your variables here
  //----------------------------------------------------------------------------------

  // Draw
  //----------------------------------------------------------------------------------
  r.BeginDrawing()

  r.ClearBackground(r.RAYWHITE)

  console.log('hello')

  r.GetKeyPressed()
  console.log(r.IsKeyDown(r.KEY_ONE))

  // console.log(r.GetKeyPressed())
  r.DrawText('some basic shapes available on raylib', 20, 20, 20, r.DARKGRAY)

  var position = {
    x: 100,
    y: 100,
  }
  var size = {
    x: 200,
    y: 150,
github RobLoach / node-raylib / examples / textures / textures_image_loading.js View on Github external
r.UnloadImage(image);   // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
//---------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose())    // Detect window close button or ESC key
{
    // Update
    //----------------------------------------------------------------------------------
    // TODO: Update your variables here
    //----------------------------------------------------------------------------------
console.log('5')
    // Draw
    //----------------------------------------------------------------------------------
    r.BeginDrawing();

        r.ClearBackground(r.RAYWHITE);

        r.DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, r.WHITE);

        r.DrawText("this IS a texture loaded from an image!", 300, 370, 10, r.GRAY);

    r.EndDrawing();
    //----------------------------------------------------------------------------------
}

// De-Initialization
//--------------------------------------------------------------------------------------
r.UnloadTexture(texture);       // Texture unloading

r.CloseWindow();                // Close window and OpenGL context
//--------------------------------------------------------------------------------------
github RobLoach / node-raylib / examples / textures / textures_image_loading.js View on Github external
// Update
    //----------------------------------------------------------------------------------
    // TODO: Update your variables here
    //----------------------------------------------------------------------------------
console.log('5')
    // Draw
    //----------------------------------------------------------------------------------
    r.BeginDrawing();

        r.ClearBackground(r.RAYWHITE);

        r.DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, r.WHITE);

        r.DrawText("this IS a texture loaded from an image!", 300, 370, 10, r.GRAY);

    r.EndDrawing();
    //----------------------------------------------------------------------------------
}

// De-Initialization
//--------------------------------------------------------------------------------------
r.UnloadTexture(texture);       // Texture unloading

r.CloseWindow();                // Close window and OpenGL context
//--------------------------------------------------------------------------------------
github taniarascia / chip8 / example.js View on Github external
********************************************************************************************/

const r = require('raylib')

// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800
const screenHeight = 450

r.InitWindow(screenWidth, screenHeight, 'raylib [shapes] example - basic shapes drawing')

r.SetTargetFPS(60)
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose()) {
  // Detect window close button or ESC key
  // Update
  //----------------------------------------------------------------------------------
  // TODO: Update your variables here
  //----------------------------------------------------------------------------------

  // Draw
  //----------------------------------------------------------------------------------
  r.BeginDrawing()

  r.ClearBackground(r.RAYWHITE)

  console.log('hello')

  r.GetKeyPressed()
  console.log(r.IsKeyDown(r.KEY_ONE))
github taniarascia / chip8 / example.js View on Github external
// TODO: Update your variables here
  //----------------------------------------------------------------------------------

  // Draw
  //----------------------------------------------------------------------------------
  r.BeginDrawing()

  r.ClearBackground(r.RAYWHITE)

  console.log('hello')

  r.GetKeyPressed()
  console.log(r.IsKeyDown(r.KEY_ONE))

  // console.log(r.GetKeyPressed())
  r.DrawText('some basic shapes available on raylib', 20, 20, 20, r.DARKGRAY)

  var position = {
    x: 100,
    y: 100,
  }
  var size = {
    x: 200,
    y: 150,
  }
  r.DrawRectangleV(position, size, r.DARKBLUE)

  r.DrawRectangleRec(
    {
      x: 50,
      y: 50,
      width: 50,
github taniarascia / chip8 / example.js View on Github external
r.GetKeyPressed()
  console.log(r.IsKeyDown(r.KEY_ONE))

  // console.log(r.GetKeyPressed())
  r.DrawText('some basic shapes available on raylib', 20, 20, 20, r.DARKGRAY)

  var position = {
    x: 100,
    y: 100,
  }
  var size = {
    x: 200,
    y: 150,
  }
  r.DrawRectangleV(position, size, r.DARKBLUE)

  r.DrawRectangleRec(
    {
      x: 50,
      y: 50,
      width: 50,
      height: 50,
    },
    r.PINK
  )

  /*
        DrawCircle(screenWidth/4, 120, 35, DARKBLUE);
        DrawRectangle(screenWidth/4*2 - 60, 100, 120, 60, RED);
        DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE);  // NOTE: Uses QUADS internally, not lines
        DrawRectangleGradientH(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD);
github taniarascia / chip8 / example.js View on Github external
console.log(r.IsKeyDown(r.KEY_ONE))

  // console.log(r.GetKeyPressed())
  r.DrawText('some basic shapes available on raylib', 20, 20, 20, r.DARKGRAY)

  var position = {
    x: 100,
    y: 100,
  }
  var size = {
    x: 200,
    y: 150,
  }
  r.DrawRectangleV(position, size, r.DARKBLUE)

  r.DrawRectangleRec(
    {
      x: 50,
      y: 50,
      width: 50,
      height: 50,
    },
    r.PINK
  )

  /*
        DrawCircle(screenWidth/4, 120, 35, DARKBLUE);
        DrawRectangle(screenWidth/4*2 - 60, 100, 120, 60, RED);
        DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE);  // NOTE: Uses QUADS internally, not lines
        DrawRectangleGradientH(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD);
        DrawTriangle((Vector2){screenWidth/4*3, 80},
                     (Vector2){screenWidth/4*3 - 60, 150},