I'm not succeeding in drawing a sprite. I use the function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
void drawSprite(SDL_Surface* imageSurface, SDL_Surface* screenSurface, int srcX, int srcY, int dstX, int dstY, int width, int height)
{
SDL_Rect srcRect;
srcRect.x = srcX;
srcRect.y = srcY;
srcRect.w = width;
srcRect.h = height;
SDL_Rect dstRect;
dstRect.x = dstX;
dstRect.y = dstY;
dstRect.w = width; // This is actually ignored by SDL_BlitSurface.
dstRect.h = height; // This is actually ignored by SDL_BlitSurface.
SDL_BlitSurface(imageSurface, &srcRect, screenSurface, &dstRect);
// fast blit from source to destination.
// ignores the -1 or -2 possible error codes.
}
Like this: drawSprite(shot, screen, 0, 0, sPosX, sPosY, 8, 8);
after defining shot using shot=SDL_LoadBMP("./shot.bmp");
The file definitely exists, otherwise the program would crash (I haven't added verification of a correct load.)
It's working perfectly - no errors whatsoever, but the shot isn't being displayed.
Could possibly be the order your displaying in. Or the shot itself - is it under the object your shooting from and not updating its x and y position so you never see it move?