c++ 在SDL2中检测SDL_Surfaces的鼠标单击

jvlzgdj9  于 2023-05-30  发布在  其他
关注(0)|答案(1)|浏览(213)

我想做一个程序,如果你选择一个曲面,它会被放到selectedPiece变量中,但我使用的是SDL_PointInRect。它给出了这个错误“的参数类型“SDL_Surface”是不兼容的参数类型“const SDL_Rect””你知道替代PointInRect是兼容的表面?

SDL_Surface* selectedPiece;
std::list<SDL_Surface*> pieces;

bool leftClick;

if (SDL_MOUSEBUTTONDOWN)
{
    if (!leftClick && windowEvent.button.button == SDL_BUTTON_LEFT)
    {
        leftClick = true;

        for (auto surface : pieces 
        {
            if (SDL_PointInRect(&mousePos, surface)) //<<<--- the sdl point in rect isnt compatible with the surface
            {
                selectedPiece = surface;
            }
        }
    }
}
jk9hmnmh

jk9hmnmh1#

因为你SDL_BlitSurface(imageSurface, NULL, windowSurface, NULL);,这意味着目标矩形的左上角在(0,0)。
适当的检查将是:

SDL_Rect surfacerect{0, 0, surface->w, surface->h};

if (SDL_PointInRect(&mousePos, &surfacerect))

相关问题