-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouse_interaction_in_raylib.cpp
More file actions
85 lines (51 loc) · 1.98 KB
/
Copy pathMouse_interaction_in_raylib.cpp
File metadata and controls
85 lines (51 loc) · 1.98 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Move the object using mouse
#include <raylib.h>
int main()
{
InitWindow(600, 500, "Move object");
Vector2 cursorPos = { 0, 0 }; // Variable to store the cursor position
int radius = 20;
SetTargetFPS(60);
while (!WindowShouldClose())
{
cursorPos = GetMousePosition(); // Get mouse position using Raylib function
HideCursor(); // hide the cursor in graphics window
BeginDrawing();
ClearBackground(RAYWHITE); // Make background white
// Draw the moving circle at the mouse position
DrawCircleV(cursorPos, radius, BLUE);
// Check if the left mouse button is pressed
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
{
break; // Exit from game loop
}
EndDrawing();
}
CloseWindow();
return 0;
}
/*
Explanation:
DrawCircleV():
This function is used to draw the circle.
This function takes three arguments.
Syntax:
DrawCircleV(center_point, radius, color);
This takes Vector2 for get center point of circle.
Vector2 is a data structure in Raylib used to represent 2D coordinates or points in a two-dimensional space.
GetMousePosition():
This function returns Vector2 as x and y coordinates of mouse cursor.
In shortly, this is returns x and y positions of mouse.
IsMouseButtonPressed():
This function is used to check if given mouse button is pressed or not.
Syntax:
IsMouseButtonPressed(mouse_button);
IsMouseButtonDown():
This function is used to check if given mouse button is continuously pressed or not.
Syntax:
IsMouseButtonDown(mouse_button);
There are mostly two key is used to check for mouse
1). MOUSE_BUTTON_LEFT and 2). MOUSE_BUTTON_RIGHT
So, this was simple functions for mouse interaction in raylib.
I hope you understand everything.
*/