Hi everyone.
i have this peace of code, and my problem is in the set() function that i created:
Code:
SDL_Surface* window = SDL_SetVideoMode(1024, 768, 32, 0);
SDL_Surface* img = SDL_LoadBMP(“ship.bmp”);
SDL_Surface* bg = SDL_LoadBMP(“background.bmp”);
int main(int argc, char** argv)
{
SDL_Init(SDL_INIT_EVERYTHING);
for (int i = 0; i < 400; ++i)
{
//SDL_BlitSurface(bg, &imgRect, window, &destRect);
set(bg, window, 0, 0);
set(img, window, 40, 700-i);
SDL_UpdateRect(window, 0, 0, 0, 0);
}
SDL_Quit();
}
heres the function:
Code:
int set(SDL_Surface* i, SDL_Surface* dest, int destX, int destY)
{
SDL_Rect imgRect;
imgRect.x = 0;
imgRect.y = 0;
SDL_Rect destRect;
destRect.x = destX;
destRect.y = destY;
SDL_BlitSurface(i, &imgRect, dest, &destRect);
}
the problem is that in main, the program only blits the bg image once, and in all the other loops the bg image is not blited. But the img image blits fine in every loop.
what am i doing wrong here??
when i use the blit function by itself it works fine, for example:
Code:
int main(int argc, char** argv)
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Rect imgRect;
imgRect.x = 0;
imgRect.y = 0;
SDL_Rect destRect;
destRect.x = 0;
destRect.y = 0;
for (int i = 0; i < 400; ++i)
{
SDL_BlitSurface(bg, &imgRect, window, &destRect);
set(img, window, 40, 700-i);
SDL_UpdateRect(window, 0, 0, 0, 0);
}
SDL_Quit();
}
like this, bg is blited in every loop cicle, but i want to be able to use my function.
Any ideas why it isnt working??[/code][/quote]