API reference / Input and time
SDL_PointInRectFloat
Function, SDL3
Tests whether a point is inside a rectangle. This is the test for a click on a button.
Declaration
#include <SDL3/SDL.h>
bool SDL_PointInRectFloat(const SDL_FPoint *p, const SDL_FRect *r);Parameters
p | The point. |
r | The rectangle. |
Return value
True for a point inside the rectangle. It returns false for a point outside, and for a NULL argument.
Example
SDL_FPoint point = { x, y };
if (SDL_PointInRectFloat(&point, &target)) {
score++;
move_target();
}See this code run in Scenes. Download the full program (.zip)
In SDL2
Use SDL_PointInFRect.