Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release
on:
push:
tags:
- 'v*'
- "v*"
jobs:
create_release:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -214,4 +214,4 @@ jobs:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./build/Release/node-raylib.node
asset_name: node-raylib-darwin-x64.node
asset_content_type: application/octet-stream
asset_content_type: application/octet-stream
17 changes: 10 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include(FetchContent)

cmake_minimum_required(VERSION 3.11)
# 2025-02-15: based on https://github.com/raysan5/raylib/blob/master/src/external/glfw/CMakeLists.txt, make sure the CMake version are between 3.4 and 3.28 or the whole raylib lib will face fatal errors
cmake_minimum_required(VERSION 3.4...3.28 FATAL_ERROR)
project (node-raylib
VERSION 0.10.0
DESCRIPTION "Node.js bindings for raylib"
Expand All @@ -11,33 +12,35 @@ if ( CMAKE_COMPILER_IS_GNUCC )
set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS} -Wno-unused-result")
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
endif()
# 2025-02-15: based on @link: https://learn.microsoft.com/en-us/cpp/build/reference/o-options-optimize-code?view=msvc-170. MSVC only accept O2 and don't have O3 optimization flag
if ( MSVC )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /w")
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
else()
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
endif()

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")

# version doesn't seem to pick correct version
#find_package(raylib 4.5 QUIET EXACT)
#find_package(raylib 5.5 QUIET EXACT)
if (NOT raylib_FOUND)
include(FetchContent)
FetchContent_Declare(
raylib
GIT_REPOSITORY https://github.com/raysan5/raylib.git
GIT_TAG 4.5.0
GIT_TAG 5.5
GIT_SHALLOW TRUE
)
FetchContent_GetProperties(raylib)
if (NOT raylib_POPULATED)
set(FETCHCONTENT_QUIET NO)
FetchContent_Populate(raylib)
FetchContent_MakeAvailable(raylib)
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(${raylib_SOURCE_DIR} ${raylib_BINARY_DIR})
endif()
endif()

Expand Down Expand Up @@ -75,7 +78,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
SUFFIX ".node"
)

target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)

target_include_directories(${PROJECT_NAME} PUBLIC
"${CMAKE_JS_INC}"
Expand Down
2,686 changes: 2,005 additions & 681 deletions docs/API.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion drm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

const raylib = require('../src/generated/node-raylib-drm')
const { format } = require('util')
const { format } = require('node:util')

// Constants
raylib.MAX_GAMEPADS = 4
Expand Down
2 changes: 1 addition & 1 deletion examples/audio/audio_module_playing.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
********************************************************************************************/

const r = require('raylib')
const r = require('../../index.js')

const MAX_CIRCLES = 64

Expand Down
4 changes: 2 additions & 2 deletions examples/audio/audio_multichannel_sound.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
*
********************************************************************************************/

const r = require('raylib')
const { join } = require('path')
const r = require('../../index.js')
const { join } = require('node:path')

// Initialization
// --------------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions examples/audio/audio_music_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*
********************************************************************************************/

const r = require('raylib')
const { join } = require('path')
const r = require('../../index.js')
const { join } = require('node:path')

// Initialization
// --------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/audio/audio_raw_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
********************************************************************************************/

const r = require('raylib')
const r = require('../../index.js')

function memcpy (src, srcOffset, dst, dstOffset, length) {
let i
Expand Down
4 changes: 2 additions & 2 deletions examples/audio/audio_sound_loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*
********************************************************************************************/

const r = require('raylib')
const { join } = require('path')
const r = require('../../index.js')
const { join } = require('node:path')

// Initialization
// --------------------------------------------------------------------------------------
Expand Down
162 changes: 92 additions & 70 deletions examples/core/core_2d_camera.js
Original file line number Diff line number Diff line change
@@ -1,136 +1,158 @@
/*******************************************************************************************
*
* raylib [core] example - 2d camera
*
* This example has been created using raylib 1.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
*
* raylib [core] example - 2d camera
*
* This example has been created using raylib 1.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
*
********************************************************************************************/

const r = require('raylib')
const r = require("../../index.js");

const MAX_BUILDINGS = 100
const MAX_BUILDINGS = 100;

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

r.InitWindow(screenWidth, screenHeight, 'raylib [core] example - 2d camera')
r.InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera");

const player = r.Rectangle(400, 280, 40, 40)
const buildings = []
const buildColors = []
const player = r.Rectangle(400, 280, 40, 40);
const buildings = [];
const buildColors = [];

let spacing = 0
let spacing = 0;

for (let i = 0; i < MAX_BUILDINGS; i++) {
const height = r.GetRandomValue(100, 800)
const height = r.GetRandomValue(100, 800);
const newBuilding = r.Rectangle(
-6000 + spacing,
screenHeight - 130 - height,
r.GetRandomValue(50, 200),
height
)
spacing += newBuilding.width
buildings.push(newBuilding)
buildColors.push(r.Color(r.GetRandomValue(200, 240), r.GetRandomValue(200, 240), r.GetRandomValue(200, 250), 255))
);
spacing += newBuilding.width;
buildings.push(newBuilding);
buildColors.push(
r.Color(
r.GetRandomValue(200, 240),
r.GetRandomValue(200, 240),
r.GetRandomValue(200, 250),
255
)
);
}

const camera = r.Camera2D(
r.Vector2(screenWidth / 2, screenHeight / 2),
r.Vector2(player.x + 20, player.y + 20),
0, 1)
0,
1
);

r.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
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
while (!r.WindowShouldClose()) {
// Detect window close button or ESC key
// Update
// ----------------------------------------------------------------------------------
if (r.IsKeyDown(r.KEY_RIGHT)) {
player.x += 2 // Player movement
camera.offset.x -= 2 // Camera displacement with player movement
player.x += 2; // Player movement
camera.offset.x -= 2; // Camera displacement with player movement
} else if (r.IsKeyDown(r.KEY_LEFT)) {
player.x -= 2 // Player movement
camera.offset.x += 2 // Camera displacement with player movement
player.x -= 2; // Player movement
camera.offset.x += 2; // Camera displacement with player movement
}

// Camera target follows player
camera.target = r.Vector2(player.x + 20, player.y + 20)
camera.target = r.Vector2(player.x + 20, player.y + 20);

// Camera rotation controls
if (r.IsKeyDown(r.KEY_A)) {
camera.rotation--
camera.rotation--;
} else if (r.IsKeyDown(r.KEY_S)) {
camera.rotation++
camera.rotation++;
}

// Limit camera rotation to 80 degrees (-40 to 40)
if (camera.rotation > 40) {
camera.rotation = 40
camera.rotation = 40;
} else if (camera.rotation < -40) {
camera.rotation = -40
camera.rotation = -40;
}

// Camera zoom controls
camera.zoom += r.GetMouseWheelMove() * 0.05
camera.zoom += r.GetMouseWheelMove() * 0.05;

if (camera.zoom > 3) camera.zoom = 3
else if (camera.zoom < 0.1) camera.zoom = 0.1
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
camera.zoom = 1.0;
camera.rotation = 0;
}
// ----------------------------------------------------------------------------------

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

r.ClearBackground(r.RAYWHITE)
r.ClearBackground(r.RAYWHITE);

r.BeginMode2D(camera)
r.BeginMode2D(camera);

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

for (let i = 0; i < MAX_BUILDINGS; i++) {
r.DrawRectangleRec(buildings[i], buildColors[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)

r.EndMode2D()

r.DrawText('SCREEN AREA', 640, 10, 20, r.RED)

r.DrawRectangle(0, 0, screenWidth, 5, r.RED)
r.DrawRectangle(0, 5, 5, screenHeight - 10, r.RED)
r.DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, r.RED)
r.DrawRectangle(0, screenHeight - 5, screenWidth, 5, r.RED)

r.DrawRectangle(10, 10, 250, 113, r.Fade(r.SKYBLUE, 0.5))
r.DrawRectangleLines(10, 10, 250, 113, r.BLUE)

r.DrawText('Free 2d camera controls:', 20, 20, 10, r.BLACK)
r.DrawText('- Right/Left to move Offset', 40, 40, 10, r.DARKGRAY)
r.DrawText('- Mouse Wheel to Zoom in-out', 40, 60, 10, r.DARKGRAY)
r.DrawText('- A / S to Rotate', 40, 80, 10, r.DARKGRAY)
r.DrawText('- R to reset Zoom and Rotation', 40, 100, 10, r.DARKGRAY)

r.EndDrawing()
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
);

r.EndMode2D();

r.DrawText("SCREEN AREA", 640, 10, 20, r.RED);

r.DrawRectangle(0, 0, screenWidth, 5, r.RED);
r.DrawRectangle(0, 5, 5, screenHeight - 10, r.RED);
r.DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, r.RED);
r.DrawRectangle(0, screenHeight - 5, screenWidth, 5, r.RED);

r.DrawRectangle(10, 10, 250, 113, r.Fade(r.SKYBLUE, 0.5));
r.DrawRectangleLines(10, 10, 250, 113, r.BLUE);

r.DrawText("Free 2d camera controls:", 20, 20, 10, r.BLACK);
r.DrawText("- Right/Left to move Offset", 40, 40, 10, r.DARKGRAY);
r.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, r.DARKGRAY);
r.DrawText("- A / S to Rotate", 40, 80, 10, r.DARKGRAY);
r.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, r.DARKGRAY);

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

// De-Initialization
// --------------------------------------------------------------------------------------
r.CloseWindow() // Close window and OpenGL context
r.CloseWindow(); // Close window and OpenGL context
// --------------------------------------------------------------------------------------
2 changes: 1 addition & 1 deletion examples/core/core_3d_camera_first_person.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
********************************************************************************************/

const r = require('raylib')
const r = require('../../index.js')

const MAX_COLUMNS = 20

Expand Down
2 changes: 1 addition & 1 deletion examples/core/core_3d_camera_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
********************************************************************************************/

const r = require('raylib')
const r = require('../../index.js')

// Initialization
// --------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/core/core_basic_window.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
********************************************************************************************/

const r = require('raylib')
const r = require('../../index.js')

// Initialization
// --------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/core/core_input_mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
********************************************************************************************/

const r = require('raylib')
const r = require('../../index.js')

// Initialization
// --------------------------------------------------------------------------------------
Expand Down
Loading