import pygame pygame.init() WIDTH, HEIGHT = 800, 600 win = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Drag Selection Debug") sprite_sheet = pygame.image.load("Spritesheet.png").convert_alpha() sheet_rect = sprite_sheet.get_rect() scale_factor = min(WIDTH / sheet_rect.width, HEIGHT / sheet_rect.height, 1) sheet_display = pygame.transform.scale(sprite_sheet, (int(sheet_rect.width * scale_factor), int(sheet_rect.height * scale_factor))) sheet_pos = (0, 0) dragging = False drag_start = (0, 0) drag_end = (0, 0) clock = pygame.time.Clock() running = True while running: clock.tick(60) win.fill((30, 30, 30)) mouse_x, mouse_y = pygame.mouse.get_pos() sheet_mouse_x = int((mouse_x - sheet_pos[0]) / scale_factor) sheet_mouse_y = int((mouse_y - sheet_pos[1]) / scale_factor) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: if 0 <= sheet_mouse_x < sheet_rect.width and 0 <= sheet_mouse_y < sheet_rect.height: dragging = True drag_start = (sheet_mouse_x, sheet_mouse_y) drag_end = drag_start print("Drag start:", drag_start) elif event.type == pygame.MOUSEMOTION: if dragging: drag_end = (sheet_mouse_x, sheet_mouse_y) print("Dragging at:", drag_end) elif event.type == pygame.MOUSEBUTTONUP and event.button == 1: if dragging: dragging = False print("Drag ended at:", (sheet_mouse_x, sheet_mouse_y)) # Calculate selection rectangle snapped to sprite grid here if you want # Draw sprite sheet win.blit(sheet_display, sheet_pos) # Draw drag rect if dragging if dragging: x1 = min(drag_start[0], drag_end[0]) * scale_factor y1 = min(drag_start[1], drag_end[1]) * scale_factor x2 = max(drag_start[0], drag_end[0]) * scale_factor y2 = max(drag_start[1], drag_end[1]) * scale_factor pygame.draw.rect(win, (255, 0, 0), pygame.Rect(x1, y1, x2 - x1, y2 - y1), 3) pygame.display.flip() pygame.quit()