Sign in to follow this  
cold_heats_.--.

Don't understand something

Recommended Posts

Hi there. I'm trying to make a simple SDL program.
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_.--.

Share this post


Link to post
Share on other sites
BeerNutts    4400
What ApochPiQ said. For what you're trying to do, you should be blitting the Sprite to the screen. So, when you blit the background again, it will overwrite the old background, and the sprite that was drawn there.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this