corregit el offset del ratoli
This commit is contained in:
@@ -458,17 +458,20 @@ void Game::handleDebugMouseDrag(float delta_time) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtener estado del ratón
|
// Obtener estado del ratón (coordenadas de ventana física)
|
||||||
float mouse_x = 0.0F;
|
float mouse_x = 0.0F;
|
||||||
float mouse_y = 0.0F;
|
float mouse_y = 0.0F;
|
||||||
SDL_MouseButtonFlags buttons = SDL_GetMouseState(&mouse_x, &mouse_y);
|
SDL_MouseButtonFlags buttons = SDL_GetMouseState(&mouse_x, &mouse_y);
|
||||||
|
|
||||||
// Convertir coordenadas de ventana a coordenadas de juego
|
// Convertir coordenadas de ventana a coordenadas lógicas del renderer
|
||||||
SDL_FRect dst_rect = Screen::get()->getGameSurfaceDstRect();
|
float render_x = 0.0F;
|
||||||
|
float render_y = 0.0F;
|
||||||
|
SDL_RenderCoordinatesFromWindow(Screen::get()->getRenderer(), mouse_x, mouse_y, &render_x, &render_y);
|
||||||
|
|
||||||
// Calcular posición en coordenadas de juego (256x192)
|
// Restar el offset del borde para obtener coordenadas del área de juego
|
||||||
float game_x = (mouse_x - dst_rect.x) * (static_cast<float>(PlayArea::WIDTH) / dst_rect.w);
|
SDL_FRect dst_rect = Screen::get()->getGameSurfaceDstRect();
|
||||||
float game_y = (mouse_y - dst_rect.y) * (static_cast<float>(PlayArea::HEIGHT) / dst_rect.h);
|
float game_x = render_x - dst_rect.x;
|
||||||
|
float game_y = render_y - dst_rect.y;
|
||||||
|
|
||||||
// Verificar si el botón izquierdo está presionado
|
// Verificar si el botón izquierdo está presionado
|
||||||
bool left_button_pressed = (buttons & SDL_BUTTON_LMASK) != 0;
|
bool left_button_pressed = (buttons & SDL_BUTTON_LMASK) != 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user