How to use the raylib.BeginDrawing function in raylib

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
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 RobLoach / node-raylib / examples / core / core_3d_camera_first_person.js View on Github external
r.SetCameraMode(camera, r.CAMERA_FIRST_PERSON); // Set a first person camera mode

r.SetTargetFPS(60);                           // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose())                // Detect window close button or ESC key
{
    // Update
    //----------------------------------------------------------------------------------
    r.UpdateCamera(camera);                  // Update camera
    //----------------------------------------------------------------------------------

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

        r.ClearBackground(r.RAYWHITE);

        r.BeginMode3D(camera);

            r.DrawPlane(r.Vector3(), r.Vector2(32, 32), r.LIGHTGRAY); // Draw ground
            r.DrawCube(r.Vector3(-16, 2.5, 0), 1, 5, 32, r.BLUE);     // Draw a blue wall
            r.DrawCube(r.Vector3(16, 2.5, 0), 1, 5, 32, r.LIME);      // Draw a green wall
            r.DrawCube(r.Vector3(0, 2.5, 16), 32, 5, 1, r.GOLD);      // Draw a yellow wall

            // Draw some cubes around
            for (let i = 0; i < MAX_COLUMNS; i++)
            {
                r.DrawCube(positions[i], 2, heights[i], 2, colors[i]);
                r.DrawCubeWires(positions[i], 2, heights[i], 2, r.MAROON);
            }
github RobLoach / node-raylib / examples / models / models_billboard.js View on Github external
r.SetCameraMode(camera, r.CAMERA_ORBITAL)  // Set an orbital camera mode

r.SetTargetFPS(60)                       // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose())            // Detect window close button or ESC key
{
    // Update
    //----------------------------------------------------------------------------------
    //r.UpdateCamera(camera);              // Update camera
    //----------------------------------------------------------------------------------

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

        r.ClearBackground(r.RAYWHITE)

        r.BeginMode3D(camera)

            r.DrawGrid(10, 1.0)        // Draw a grid

            r.DrawBillboard(camera, bill, billPosition, 2.0, r.WHITE)

        r.EndMode3D()

        r.DrawFPS(10, 10)

    r.EndDrawing()
    //----------------------------------------------------------------------------------
}
github RobLoach / node-raylib / examples / audio / audio_sound_loading.js View on Github external
r.SetTargetFPS(60)               // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose())    // Detect window close button or ESC key
{
    // Update
    //----------------------------------------------------------------------------------
    if (r.IsKeyPressed(r.KEY_SPACE)) r.PlaySound(fxWav)      // Play WAV sound
    if (r.IsKeyPressed(r.KEY_ENTER)) r.PlaySound(fxOgg)      // Play OGG sound
    //----------------------------------------------------------------------------------

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

        r.ClearBackground(r.RAYWHITE)

        r.DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, r.LIGHTGRAY)
        r.DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, r.LIGHTGRAY)

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

// De-Initialization
//--------------------------------------------------------------------------------------
r.UnloadSound(fxWav)     // Unload sound data
r.UnloadSound(fxOgg)     // Unload sound data

r.CloseAudioDevice()     // Close audio device
github RobLoach / node-raylib / examples / core / core_2d_camera.js View on Github external
camera.zoom += r.GetMouseWheelMove()*0.05;

  if (camera.zoom > 3) camera.zoom = 3
  else if (camera.zoom < 0.1) camera.zoom = 0.1

  // Camera reset (zoom and rotation)
  if (r.IsKeyPressed(r.KEY_R))
  {
      camera.zoom = 1.0
      camera.rotation = 0
  }
  //----------------------------------------------------------------------------------

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

    r.ClearBackground(r.RAYWHITE);

    r.BeginMode2D(camera);

      r.DrawRectangle(-6000, 320, 13000, 8000, r.DARKGRAY);

      for (var i = 0; i < MAX_BUILDINGS; i++) {
        r.DrawRectangleRec(buildings[i], buildColors[i]);
      }

      r.DrawRectangleRec(player, r.RED);

      r.DrawLine(camera.target.x, -screenHeight*10, camera.target.x, screenHeight*10, r.GREEN);
      r.DrawLine(-screenWidth*10, camera.target.y, screenWidth*10, camera.target.y, r.GREEN);
github RobLoach / node-raylib / templates / simple_game / simple_game.js View on Github external
{
            // TODO: Update ENDING screen variables here!

            // Press enter to return to TITLE screen
            if (r.IsKeyPressed(r.KEY_ENTER) || r.IsGestureDetected(r.GESTURE_TAP))
            {
                currentScreen = 'TITLE'
            }
        } break;
        default: break;
    }
    //----------------------------------------------------------------------------------

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

        r.ClearBackground(r.RAYWHITE)

        switch(currentScreen)
        {
            case 'LOGO':
            {
                // TODO: Draw LOGO screen here!
                r.DrawText("LOGO SCREEN", 20, 20, 40, r.LIGHTGRAY)
                r.DrawText("WAIT for 2 SECONDS...", 290, 220, 20, r.GRAY)

            } break
            case 'TITLE':
            {
                // TODO: Draw TITLE screen here!
                r.DrawRectangle(0, 0, screenWidth, screenHeight, r.GREEN)
github RobLoach / node-raylib / examples / shapes / shapes_basic_shapes.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);

        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({
github taniarascia / chip8 / scripts / native.js View on Github external
// Interpret key data
  const rawKeyPressed = r.GetKeyPressed()
  const keyIndex = nativeKeyMap.findIndex(key => rawKeyPressed === key)

  // Keydown event
  if (keyIndex) {
    cpu.interface.setKeys(keyIndex)
  } else {
    // Keyup event
    cpu.interface.resetKeys()
  }

  cpu.step()

  r.BeginDrawing()

  cpu.interface.frameBuffer.forEach((y, i) => {
    y.forEach((x, j) => {
      if (x) {
        r.DrawRectangleRec(
          {
            x: j * multiplier,
            y: i * multiplier,
            width: multiplier,
            height: multiplier,
          },
          r.GREEN
        )
      } else {
        r.DrawRectangleRec(
          {
github RobLoach / node-raylib / examples / core / core_input_mouse.js View on Github external
ballPosition = r.GetMousePosition()

    if (r.IsMouseButtonPressed(r.MOUSE_LEFT_BUTTON)) {
        ballColor = r.MAROON
    }
    else if (r.IsMouseButtonPressed(r.MOUSE_MIDDLE_BUTTON)) {
        ballColor = r.LIME
    }
    else if (r.IsMouseButtonPressed(r.MOUSE_RIGHT_BUTTON)) {
        ballColor = r.DARKBLUE
    }
    //----------------------------------------------------------------------------------

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

        r.ClearBackground(r.RAYWHITE)

        r.DrawCircleV(ballPosition, 40, ballColor)

        r.DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, r.DARKGRAY)

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

// De-Initialization
//--------------------------------------------------------------------------------------
r.CloseWindow()        // Close window and OpenGL context
//--------------------------------------------------------------------------------------