After setting the video mode and loading the background and sprite circle, basically it takes the mouse pointer coordinates and draws the circle at that location.
This is the code
[source lang="cpp"]#include <SDL/SDL.h>#include <SDL/SDL_Image.h>int main(int argc, char** argv){ SDL_Init(SDL_INIT_EVERYTHING); SDL_Surface *screen=NULL; SDL_Surface *circle=NULL; SDL_Surface *backgrd=NULL; SDL_Rect crc; crc.w=160; crc.h=120; crc.x=crc.y=0; circle=IMG_Load("circle.png"); backgrd=IMG_Load("img.bmp"); screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE); bool run = true; SDL_Rect mouser; mouser.x=0;mouser.y=0; SDL_Event event; SDL_BlitSurface(backgrd,NULL,screen,NULL); SDL_Flip(screen); while(run) { while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: run = false; break; case SDL_MOUSEBUTTONDOWN: mouser.x=event.button.x; mouser.y=event.button.y; break; } } SDL_BlitSurface(backgrd,NULL,screen,NULL); SDL_BlitSurface(circle,NULL,backgrd,&mouser); SDL_Flip(screen); SDL_Delay(2000); } SDL_FreeSurface(backgrd); SDL_FreeSurface(circle); SDL_Quit(); return 0;}[/source]
I've set the delay so I can see the sprite before it gets deleted.
The problem is, sprites do not get deleted, that is what I don't understand.
I mean , shouldn't they be "overwritten" each time I call SDL_Blitsurface at line 46 ?
Isn't that how games are rendered ? (Load background, load tiles, load sprite etc etc )
Edited by cold_heats_.--., 27 June 2012 - 05:51 PM.






