Page 1 of 1

SDL Motion/Visual studio?

Posted: Sat Oct 01, 2011 2:39 am
by treyrust
So, I'm trying to make pong... I've got a lot of the none flashy stuff setup but I'm having one problem - My motion is acting weird, it's only moving one pixel and then it stops>UNLESSSS for some reason I move the mouse and then it works for which I have no idea...

Here's my main loop:

Code: Select all

	Uint8 *keystates = NULL;
	while(run == true)
	{
		keystates = SDL_GetKeyState(NULL);
		while(SDL_PollEvent(&events))
		{

			if(keystates[SDLK_UP])
			{
				player.moveUp();
			}
			if(keystates[SDLK_DOWN])
			{
				player.moveDown();
			}
			if(events.type == SDL_QUIT)
			{
				run = false;
			}
		}


		background.blit();
		player.blit();
		
		SDL_Flip(General::screen);
		SDL_Delay(1);
	}
Here is the blit() member function:

Code: Select all

void Entity::blit()
{
	SDL_BlitSurface(image,NULL,General::screen,&offset);
}

Here's the moveUp() function, the moveDown() function is almost identical:

Code: Select all

void Padel::moveUp()
{
	if(offset.y != General::YPADDING)
	{
		offset.y -= 10;
	}
}

From what I've done on linux, and looking at the lazy foo tutorial it looks almost identical, but it's not working right in visual studio?

It works when I move the mouse, however.

Re: SDL Motion/Visual studio?

Posted: Sat Oct 01, 2011 4:00 am
by treyrust
Ah, well... I've figured it out myself, for some dumbass reason I was checking the keystates in the poll-event loop... I had a feeling something fishy was going on with that, since it only worked with I moved the mouse and that just meant that there was an event put in the queue and thus it ended up checking the keystates then and only then...

This is also why I rarely ask stupid questions, because I can figure them out myself if I'm not being brain-deaded lazy...