Original Post
I made my sprite move with the mouse but everytime I move it redraws to the screen what can I do to fix this?
[source lang="cpp"]#include "SDL/SDL.h"
#include
int x;
int y;
void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination )
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface(source, NULL, destination, &offset);
}
int main(int argc, char* args[])
{
//images/ints
SDL_Event event;
SDL_Surface* sprite = NULL;
SDL_Surface* back = NULL;
SDL_Surface* screen = NULL;
back = SDL_LoadBMP("back.bmp");
sprite = SDL_LoadBMP("char.bmp");
bool done = true;
//init
SDL_Init(SDL_INIT_EVERYTHING);
screen = SDL_SetVideoMode(560, 560, 32, SDL_SWSURFACE);
SDL_WM_SetCaption("Game", NULL);
apply_surface(0, 0, back, screen);
SDL_SetColorKey(sprite, SDL_SRCCOLORKEY, SDL_MapRGB(sprite->format, 255, 0, 255));
while (done)
{
if (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
{
done = false;
}
if(event.type == SDL_MOUSEMOTION)
{
x = event.motion.x;
y = event.motion.y;
apply_surface(x, y, sprite, screen);
}
}
SDL_ShowCursor(SDL_DISABLE);
SDL_Flip(screen);
}
SDL_FreeSurface(sprite);
SDL_FreeSurface(back);
return 0;
}[/source]
[source lang="cpp"]#include "SDL/SDL.h"
#include
int x;
int y;
void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination )
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface(source, NULL, destination, &offset);
}
int main(int argc, char* args[])
{
//images/ints
SDL_Event event;
SDL_Surface* sprite = NULL;
SDL_Surface* back = NULL;
SDL_Surface* screen = NULL;
back = SDL_LoadBMP("back.bmp");
sprite = SDL_LoadBMP("char.bmp");
bool done = true;
//init
SDL_Init(SDL_INIT_EVERYTHING);
screen = SDL_SetVideoMode(560, 560, 32, SDL_SWSURFACE);
SDL_WM_SetCaption("Game", NULL);
apply_surface(0, 0, back, screen);
SDL_SetColorKey(sprite, SDL_SRCCOLORKEY, SDL_MapRGB(sprite->format, 255, 0, 255));
while (done)
{
if (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
{
done = false;
}
if(event.type == SDL_MOUSEMOTION)
{
x = event.motion.x;
y = event.motion.y;
apply_surface(x, y, sprite, screen);
}
}
SDL_ShowCursor(SDL_DISABLE);
SDL_Flip(screen);
}
SDL_FreeSurface(sprite);
SDL_FreeSurface(back);
return 0;
}[/source]