rayjs/examples/input_mouse_wheel.js

41 lines
1.6 KiB
JavaScript
Raw Normal View History

2023-05-11 20:10:40 +00:00
// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800;
const screenHeight = 450;
2023-05-14 20:19:47 +00:00
initWindow(screenWidth, screenHeight, "raylib [core] example - input mouse wheel");
2023-05-11 20:10:40 +00:00
let boxPositionY = screenHeight/2 - 40;
let scrollSpeed = 4; // Scrolling speed in pixels
2023-05-14 20:19:47 +00:00
setTargetFPS(60); // Set our game to run at 60 frames-per-second
2023-05-11 20:10:40 +00:00
//--------------------------------------------------------------------------------------
// Main game loop
2023-05-14 20:19:47 +00:00
while (!windowShouldClose()) // Detect window close button or ESC key
2023-05-11 20:10:40 +00:00
{
// Update
//----------------------------------------------------------------------------------
2023-05-14 20:19:47 +00:00
boxPositionY -= (getMouseWheelMove()*scrollSpeed);
2023-05-11 20:10:40 +00:00
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
2023-05-14 20:19:47 +00:00
beginDrawing();
2023-05-11 20:10:40 +00:00
2023-05-14 20:19:47 +00:00
clearBackground(RAYWHITE);
2023-05-11 20:10:40 +00:00
2023-05-14 20:19:47 +00:00
drawRectangle(screenWidth/2 - 40, boxPositionY, 80, 80, MAROON);
2023-05-11 20:10:40 +00:00
2023-05-14 20:19:47 +00:00
drawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, GRAY);
drawText("Box position Y: " + boxPositionY, 10, 40, 20, LIGHTGRAY);
2023-05-11 20:10:40 +00:00
2023-05-14 20:19:47 +00:00
endDrawing();
2023-05-11 20:10:40 +00:00
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
2023-05-14 20:19:47 +00:00
closeWindow(); // Close window and OpenGL context
2023-05-11 20:10:40 +00:00
//--------------------------------------------------------------------------------------