SDL_RenderCopy() 不适用于数组

SDL_RenderCopy() doesn't work with array

本文关键字:不适用 适用于 数组 RenderCopy SDL      更新时间:2023-10-16

我在互联网和这里搜索过,我只找到了 1 个带有矩形数组的井帖子SDL_RenderCopy。(据我了解)没有答案,但我的问题和那里一样。有什么方法可以做到这一点吗?

SDL_RenderCopy(renderer, texture, &rects[index], &sprPos);

调试内容如下:

Error   1   error C2664: 'int SDL_RenderCopy(SDL_Renderer *,SDL_Texture *,const SDL_Rect *,const SDL_Rect *)' : cannot convert argument 3 from 'SDL_Rect **' to 'const SDL_Rect *'  c:userskushnirenkodocumentsvisual studio 2013projectssdl_projectsdl_projectmain.cpp 96  1   SDL_Project
2   IntelliSense: argument of type "SDL_Rect **" is incompatible with parameter of type "const SDL_Rect *"  c:UserskushnirenkoDocumentsVisual Studio 2013ProjectsSDL_ProjectSDL_Projectmain.cpp 96  37  SDL_Project

我解决了这个问题。有一种方法可以将数组设置为 SDL_RenderCopy。在这里:

// Sprites atlas regions
    SDL_Rect left = { sprite * 32, 32, 32, 32 };
    SDL_Rect right = { sprite * 32, 64, 32, 32 };
    SDL_Rect up = { sprite * 32, 96, 32, 32 };
    SDL_Rect down = { sprite * 32, 0, 32, 32 };
    SDL_Rect leftIdle = { 32, 32, 32, 32 };
    SDL_Rect rightIdle = { 32, 64, 32, 32 };
    SDL_Rect upIdle = { 32, 96, 32, 32 };
    SDL_Rect downIdle = { 32, 0, 32, 32 };
    // End of sprite atlas
    sprPos = { x, y, 32, 32 };
    spritesCoords[0] = left;
    spritesCoords[1] = right;
    spritesCoords[2] = up;
    spritesCoords[3] = down;
    spritesCoords[4] = leftIdle;
    spritesCoords[5] = rightIdle;
    spritesCoords[6] = upIdle;
    spritesCoords[7] = downIdle;
    sprFrame = spritesCoords[spriteIndex]; // This is solutuion.
    SDL_RenderClear(renderer);
    SDL_RenderCopy(renderer, texture, &sprFrame, &sprPos);
    SDL_RenderPresent(renderer);
相关文章: