Description
Please, before submitting a new issue verify and check:
- I tested it on latest raylib version from master branch
- I checked there is no similar issue already reported
- I checked the documentation on the wiki
- My code has no errors or misuse of raylib
Issue description
While working on a game idea I noticed that mouse clicks don't get registered properly. I wrote a much simplified version of the game loop in Go and in C and observed the same problem.
Basically when you click "swiftly" the code below doesn't always print when the mouse button is pressed. When you hold the button for a bit it does print every time.
Furthermore if you set the frame-rate to 0 (no wait) then it works all the time even with swift presses. I haven't tested if there was actual "rendering load" if it would still work all the time... but in my dumbed down, no-render version it does.
We had a chat with @JeffM2501 in Discord here https://discord.com/channels/426912293134270465/1335478227551912016
The Go library I used packages Raylib-5.5 and I installed Raylib-5.5 through Brew as well for the C version.
Environment
- Chip: Apple M2 Max
- MacOS: 14.6.1 (23G93)
Code Example
Go Version:
package main
import (
"fmt"
rl "github.com/gen2brain/raylib-go/raylib"
)
const (
windowTitle = "Test"
defaultScreenWidth = 1024
defaultScreenHeight = 720
)
var (
screenWidth int32 = defaultScreenWidth
screenHeight int32 = defaultScreenHeight
)
func watchWindowResize() {
screenWidth = int32(rl.GetScreenWidth())
screenHeight = int32(rl.GetScreenHeight())
}
func watchUserInput() {
if rl.IsMouseButtonPressed(rl.MouseButtonLeft) {
fmt.Printf("left mouse button pressed\n")
}
if rl.IsMouseButtonDown(rl.MouseButtonLeft) {
fmt.Printf("left mouse button down\n")
}
if rl.IsMouseButtonUp(rl.MouseButtonLeft) {
fmt.Printf("left mouse button up\n")
}
if rl.IsMouseButtonReleased(rl.MouseButtonLeft) {
fmt.Printf("left mouse button released\n")
}
}
func main() {
rl.SetConfigFlags(rl.FlagWindowResizable)
rl.InitWindow(screenWidth, screenHeight, windowTitle)
rl.SetTargetFPS(60)
camera := rl.Camera3D{
Position: rl.NewVector3(0.0, 0.0, 0.0),
Target: rl.NewVector3(0.0, 0.0, 0.0),
Up: rl.NewVector3(0.0, 1.0, 0.0),
Fovy: 45.0,
Projection: rl.CameraPerspective,
}
for !rl.WindowShouldClose() {
watchWindowResize()
watchUserInput()
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
rl.BeginMode3D(camera)
rl.EndMode3D()
rl.DrawFPS(10, 10)
rl.EndDrawing()
}
rl.CloseWindow()
}
C Version
#include "raylib.h"
#include <stdio.h>
int main(void) {
const int screenWidth = 1024;
const int screenHeight = 720;
InitWindow(screenWidth, screenHeight, "Test");
SetTargetFPS(60);
while (!WindowShouldClose()) {
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
printf("Left mouse button pressed\n");
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
printf("Left mouse button released\n");
BeginDrawing();
ClearBackground(RAYWHITE);
DrawFPS(10, 10);
EndDrawing();
}
CloseWindow();
return 0;
}