-4

I've searched in internet and here and I found only 1 well post SDL_RenderCopy with an array of Rectangles. There's (as I understand) no answer, but my problem is same as there. Is any way to make this work?

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

Here's what debug says:

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:\users\kushnirenko\documents\visual studio 2013\projects\sdl_project\sdl_project\main.cpp 96  1   SDL_Project

2   IntelliSense: argument of type "SDL_Rect **" is incompatible with parameter of type "const SDL_Rect *"  c:\Users\kushnirenko\Documents\Visual Studio 2013\Projects\SDL_Project\SDL_Project\main.cpp 96  37  SDL_Project
Community
  • 1
  • 1
  • 1
    _`Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.`_ – πάντα ῥεῖ Jan 05 '15 at 19:29
  • Your answer isn't even intuitive. OP, have you removed the ampersand from argument 3? Unless a double pointer is expected, using an ampersand isn't prime; arrays are passed by reference anyway. – Poriferous Jan 05 '15 at 21:28

1 Answers1

0

I resolve this problem. There's a way to set an array to SDL_RenderCopy. Here it is:

// 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);