#include "raylib.h"
int main(void)
{
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - input mouse wheel");
int boxPositionY = screenHeight/2 - 40;
int scrollSpeed = 4; // Scrolling speed in pixels
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
while (!WindowShouldClose()) // Detect window close button or ESC key
{
boxPositionY -= (GetMouseWheelMove()*scrollSpeed);
BeginDrawing();
ClearBackground(RAYWHITE);
DrawRectangle(screenWidth/2 - 40, boxPositionY, 80, 80, MAROON);
DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, GRAY);
DrawText(FormatText("Box position Y: %03i", boxPositionY), 10, 40, 20, LIGHTGRAY);
EndDrawing();
}
CloseWindow(); // Close window and OpenGL context
return 0;
}
use raylib::prelude::*;
fn main() {
let screen_width = 800;
let screen_height = 450;
let (mut rl, thread) = raylib::init()
.size(screen_width, screen_height)
.title("raylib [core] example - input mouse wheel")
.build();
let mut box_position_y = screen_height / 2 - 40;
let scroll_speed = 4;
rl.set_target_fps(60); // Set our game to run at 60 frames-per-second
while !rl.window_should_close() {
box_position_y -= rl.get_mouse_wheel_move() * scroll_speed;
let mut d = rl.begin_drawing(&thread);
d.clear_background(Color::RAYWHITE);
d.draw_rectangle(screen_width / 2 - 40, box_position_y, 80, 80, Color::MAROON);
d.draw_text(
"Use mouse wheel to move the cube up and down!",
10,
10,
20,
Color::DARKGRAY,
);
d.draw_text(
&format!("Box position Y: {}", box_position_y), // this is the rust equivalent to FormatText()
10,
40,
20,
Color::LIGHTGRAY,
);
}
}
#include "raylib.h"
int main(void)
{
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input");
Vector2 ballPosition = { -100.0f, -100.0f };
Color ballColor = DARKBLUE;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
while (!WindowShouldClose()) // Detect window close button or ESC key
{
ballPosition = GetMousePosition();
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) ballColor = MAROON;
else if (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) ballColor = LIME;
else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) ballColor = DARKBLUE;
BeginDrawing();
ClearBackground(RAYWHITE);
DrawCircleV(ballPosition, 40, ballColor);
DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY);
EndDrawing();
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
return 0;
}
use raylib::prelude::MouseButton::*;
use raylib::prelude::*;
fn main() {
let screen_width = 800.0;
let screen_height = 450.0;
let (mut rl, thread) = raylib::init()
.size(screen_width as i32, screen_height as i32)
.title("Raylib [core] example - mouse input")
.build();
let mut ball_color = Color::DARKBLUE;
rl.set_target_fps(60); // Set our game to run at 60 frames-per-second
while !rl.window_should_close() {
if rl.is_mouse_button_pressed(MOUSE_LEFT_BUTTON) {
ball_color = Color::MAROON;
} else if rl.is_mouse_button_pressed(MOUSE_MIDDLE_BUTTON) {
ball_color = Color::LIME;
} else if rl.is_mouse_button_pressed(MOUSE_RIGHT_BUTTON) {
ball_color = Color::DARKBLUE;
}
let mut d = rl.begin_drawing(&thread);
d.clear_background(Color::RAYWHITE);
d.draw_text(
"move ball with mouse and click mouse button to change color",
10,
10,
20,
Color::DARKGRAY,
);
d.draw_circle_v(d.get_mouse_position(), 50.0, ball_color);
}
}
#include "raylib.h"
int main(void)
{
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input");
Vector2 ballPosition = { (float)screenWidth/2, (float)screenHeight/2 };
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
while (!WindowShouldClose()) // Detect window close button or ESC key
{
if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 2.0f;
if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 2.0f;
if (IsKeyDown(KEY_UP)) ballPosition.y -= 2.0f;
if (IsKeyDown(KEY_DOWN)) ballPosition.y += 2.0f;
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("move the ball with arrow keys", 10, 10, 20, DARKGRAY);
DrawCircleV(ballPosition, 50, MAROON);
EndDrawing();
}
CloseWindow(); // Close window and OpenGL context
return 0;
}
use raylib::prelude::KeyboardKey::*;
use raylib::prelude::*;
fn main() {
let screen_width = 800.0;
let screen_height = 450.0;
let (mut rl, thread) = raylib::init()
.size(screen_width as i32, screen_height as i32)
.title("raylib [core] example - keyboard input")
.build();
let mut ball_position = Vector2 {
x: screen_width / 2.0,
y: screen_height / 2.0,
};
rl.set_target_fps(60); // Set our game to run at 60 frames-per-second
while !rl.window_should_close() {
if rl.is_key_down(KEY_RIGHT) {
ball_position.x += 2.0;
}
if rl.is_key_down(KEY_LEFT) {
ball_position.x -= 2.0;
}
if rl.is_key_down(KEY_UP) {
ball_position.y -= 2.0;
}
if rl.is_key_down(KEY_DOWN) {
ball_position.y += 2.0;
}
let mut d = rl.begin_drawing(&thread);
d.clear_background(Color::RAYWHITE);
d.draw_text("move the ball with arrow keys", 10, 10, 20, Color::DARKGRAY);
d.draw_circle_v(ball_position, 50.0, Color::MAROON);
}
}