Original Post
In the following program how come if you are pushing up and down at the same time and then just one immediately after, it won't move? P.S what are the code tabs again?
edited by evolutional: The code tabs are [ source ][ /source ] (without spaces). See the FAQ for more information [smile] [Edited by - evolutional on November 22, 2004 1:55:22 PM]
#include <stdlib.h>
#include <SDL\SDL.h>
#include <SDL\SDL_gfxPrimitives.h>
void Slock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
if ( SDL_LockSurface(screen) < 0 )
{
return;
}
}
}
void Sulock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
SDL_UnlockSurface(screen);
}
}
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_VIDEO);
SDL_Surface *screen = SDL_SetVideoMode(640,480,32,SDL_HWSURFACE|SDL_DOUBLEBUF);
atexit(SDL_Quit);
SDL_WM_SetCaption("Phlong",NULL);
int y=0;
bool done = false;
while(done == false)
{
SDL_Event event;
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT ) { done = true; }
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }
}
}
SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0));
Slock(screen);
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_UP ) y-=5 ;
if ( event.key.keysym.sym == SDLK_DOWN ) y+=5 ;
}
boxRGBA(screen, 5, y, 25, y+80, 255,255,255,255);
Sulock(screen);
SDL_Flip(screen);
}
}
edited by evolutional: The code tabs are [ source ][ /source ] (without spaces). See the FAQ for more information [smile] [Edited by - evolutional on November 22, 2004 1:55:22 PM]