tags:

views:

45

answers:

1

Hello there, I'm working on some SDL stuff and I've run into some trouble when trying to set the location of a loaded BMP.

Here's the code.

while(event.type != SDL_QUIT) //The game loop that does everything
{
    SDL_Rect *location;
    location = SDL_Rect(600,400,0,0);
    SDL_PollEvent(&event); //This "polls" the event
    //Drawing stuff goes here
    SDL_BlitSurface(zombie, NULL, buffer, &location);
    SDL_Flip(buffer); //Draw
}

It won't compile. What am I doing wrong?

+3  A: 

SDL_Rect is just a simple struct, and since SDL is written in C it does not have constructors defined.
So just use the struct initialization syntax (and be careful of the declaration order of the struct's members):

SDL_Rect location = {0,0,600,400};

or explicitly initialize each of it's members (safer in case somebody decides to re-arange the order of the struct's members):

SDL_Rect location;
location.h = 600;
location.w = 400;
location.x = 0;
location.y = 0;
Eugen Constantin Dinca
I didn't know it was written in C, thanks for telling me that and giving me a legit answer! :D
Lemmons