-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathcore_input_mouse.js
More file actions
59 lines (46 loc) · 2.08 KB
/
core_input_mouse.js
File metadata and controls
59 lines (46 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*******************************************************************************************
*
* raylib [core] example - Mouse input
*
* This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
const r = require('../../index.js')
// Initialization
// --------------------------------------------------------------------------------------
const screenWidth = 800
const screenHeight = 450
r.InitWindow(screenWidth, screenHeight, 'raylib [core] example - mouse input')
let ballPosition = r.Vector2(-100, -100)
let ballColor = r.DARKBLUE
r.SetTargetFPS(60)
// ---------------------------------------------------------------------------------------
// Main game loop
while (!r.WindowShouldClose()) { // Detect window close button or ESC key
// Update
// ----------------------------------------------------------------------------------
ballPosition = r.GetMousePosition()
if (r.IsMouseButtonPressed(r.MOUSE_BUTTON_LEFT)) {
ballColor = r.MAROON
} else if (r.IsMouseButtonPressed(r.MOUSE_BUTTON_MIDDLE)) {
ballColor = r.LIME
} else if (r.IsMouseButtonPressed(r.MOUSE_BUTTON_RIGHT)) {
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
// --------------------------------------------------------------------------------------