core_mouse_wheel.lua 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. -------------------------------------------------------------------------------------------
  2. --
  3. -- raylib [core] examples - Mouse wheel
  4. --
  5. -- This example has been created using raylib 1.6 (www.raylib.com)
  6. -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. --
  8. -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
  9. --
  10. -------------------------------------------------------------------------------------------
  11. -- Initialization
  12. -------------------------------------------------------------------------------------------
  13. local screenWidth = 800
  14. local screenHeight = 450
  15. InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse wheel")
  16. local boxPositionY = screenHeight/2 - 40
  17. local scrollSpeed = 4 -- Scrolling speed in pixels
  18. SetTargetFPS(60) -- Set target frames-per-second
  19. ----------------------------------------------------------------------------------------
  20. -- Main game loop
  21. while not WindowShouldClose() do -- Detect window close button or ESC key
  22. -- Update
  23. ------------------------------------------------------------------------------------
  24. boxPositionY = boxPositionY - (GetMouseWheelMove()*scrollSpeed)
  25. ------------------------------------------------------------------------------------
  26. -- Draw
  27. ------------------------------------------------------------------------------------
  28. BeginDrawing()
  29. ClearBackground(RAYWHITE)
  30. DrawRectangle(screenWidth/2 - 40, boxPositionY, 80, 80, MAROON)
  31. DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, GRAY)
  32. DrawText(string.format("Box position Y: %03i", boxPositionY), 10, 40, 20, LIGHTGRAY)
  33. EndDrawing()
  34. ------------------------------------------------------------------------------------
  35. end
  36. -- De-Initialization
  37. ----------------------------------------------------------------------------------------
  38. CloseWindow() -- Close window and OpenGL context
  39. ----------------------------------------------------------------------------------------