i try to make a simple touch on a rect thats change the color. But i cabt fix it. At the moment i can touch everywhere on the screen and the color from the rect change. What could i do that the touch should only work when i touch the rect? Here is my code:
#include <SDL2/SDL.h>
int main() {
SDL_Window *window = NULL; window = SDL_CreateWindow("touch test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
// Setup renderer
SDL_Renderer *renderer = NULL;
renderer = SDL_CreateRenderer(window, 0, SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor(renderer, 0, 255, 25, 255); // Clear winow
SDL_SetRenderDrawColor(renderer, 255, 0, 255, 25);
SDL_Rect r {500, 500, 200, 200};
SDL_Point tloc = {r.w/2, r.h/2};
SDL_Event event;
while(true) {
while(SDL_PollEvent(&event) != 0)
{
if(event.type == SDL_FINGERDOWN){
tloc.x = event.tfinger.x * r.w ;
tloc.y = event.tfinger.y * r.h;
SDL_SetRenderDrawColor(renderer, 55, 220, 5, 255);
}
SDL_RenderFillRect(renderer, &r); SDL_RenderPresent(renderer);
}
}
SDL_DestroyWindow(window);
SDL_Quit();
}