SDL 让我在 FillRect 的糟糕旅程中

SDL is sent me on a bad trip with FillRect

    SDL_Rect r3;
    r3.h = 10;
    r3.w = 10;
    r3.x = 10;
    r3.y = 10;

    SDL_Rect r4;
    r3.h = 10;
    r3.w = 10;
    r3.x = 20;
    r3.y = 20;

    SDL_FillRect(surface, &r3, SDL_MapRGB(surface->format, 100, 0 ,100));
    SDL_FillRect(surface, &r4, SDL_MapRGB(surface->format, 100, 100 ,0));

太疯狂了,而且很奇怪。也许我不知道什么,但 R4 是 R3。不,我没疯,它会在同一个地方绘制 r3 和 r4。

我注释掉了 SDL_FillRect(surface, &r4, SDL_MapRGB(surface->format, 100, 100 ,0));,它仍然在 r4 线处绘制矩形。这让我发疯。

   SDL_Rect r3;
    r3.h = 10;
    r3.w = 10;
    r3.x = 10;
    r3.y = 10;

    SDL_Rect r4;
    r3.h = 10;
    r3.w = 10;
    r3.x = 200;
    r3.y = 200;

    //SDL_FillRect(surface, &r3, SDL_MapRGB(surface->format, 100, 0 ,100));
    SDL_FillRect(surface, &r4, SDL_MapRGB(surface->format, 100, 100 ,0));

现在R4根本就不画了

    SDL_Rect r;
    r.w = n.left->width;
    r.h = n.left->height;
    r.x = n.left->position.x;
    r.y = n.left->position.y;

    
    SDL_Rect r2;
    r.w = (int)n.right->width;
    r.h = (int)n.right->height;
    r.x = (int)n.right->position.x;
    r.y = (int)n.right->position.y;

    SDL_Rect r3;
    r3.h = 10;
    r3.w = 10;
    r3.x = 10;
    r3.y = 10;

    SDL_Rect r4;
    r3.h = 10;
    r3.w = 10;
    r3.x = 200;
    r3.y = 200;

    //SDL_FillRect(surface, &r3, SDL_MapRGB(surface->format, 100, 0 ,100));
    SDL_FillRect(surface, &r3, SDL_MapRGB(surface->format, 100, 100 ,0));

所以基本上r淹没在应该画r2的地方,r2没有画,r3画在r4应该画的地方,r4没有画。卧槽

声明 SDL_rect r4 后,您设置 r3 的坐标

SDL_Rect r4;
r3.h = 10;
r3.w = 10;
r3.x = 200;
r3.y = 200;

这可能会导致 r4 的坐标值未初始化。这应该有效:

SDL_Rect r3;
r3.h = 10;
r3.w = 10;
r3.x = 10;
r3.y = 10;

//Set r4's coordinates instead of r3's
SDL_Rect r4;
r4.h = 10;
r4.w = 10;
r4.x = 200;
r4.y = 200;

SDL_FillRect(surface, &r3, SDL_MapRGB(surface->format, 100, 0 ,100));
SDL_FillRect(surface, &r4, SDL_MapRGB(surface->format, 100, 100 ,0))