绘制SDL_Rect不起作用

时间:2013-08-22 08:09:47

标签: c++ events sdl draw rect

我正在尝试使用SDL在C ++中构建RTS。现在我正在尝试制作一个矩形,它将选择单位(可调整大小的选择框)。它将是一个透明的黄色矩形。 当我运行程序并尝试选择multiplyunits。没有任何事情发生(我的意思是绘制矩形。尚未选择)

这是代码(在main.cpp中):

...
Uint32 selection_colour;
SDL_Rect box_rect;
int M1X = 0;
int M1Y = 0;
int M2X = 0;
int M2Y = 0;

int W;
int H;
...
void init()
{
...
selection_colour = SDL_MapRGBA(screen->format, 0xFF, 0xFF, 0, 0.3);
...
}
...
while(running)
{
    while(SDL_PollEvent(&event))
    {
        if(event.type == SDL_MOUSEBUTTONDOWN)
        {

            if(event.button.button == SDL_BUTTON_LEFT)
            {

                M2X = event.motion.x;
                M2Y = event.motion.y;

                W = M2X - M1X;
                H = M2Y - M1Y;

                box_rect.x = M1X;
                box_rect.y = M1Y;
                box_rect.w = W;
                box_rect.h = H;

            }

        }else
        {
            M1X = event.motion.x;
            M1Y = event.motion.y;
        }
    }

    SDL_FillRect(screen, &box_rect, selection_colour);

    SDL_Flip(screen);
}

任何建议??

0 个答案:

没有答案