SDL Motion/Visual studio?

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
treyrust
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 36
Joined: Thu Jul 21, 2011 4:32 pm
Current Project: Between projects
Favorite Gaming Platforms: PS1/2/3/P, NES, Wii, Genesis, Dreamcast, GBA, DS
Programming Language of Choice: C++

SDL Motion/Visual studio?

Post 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.
User avatar
treyrust
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 36
Joined: Thu Jul 21, 2011 4:32 pm
Current Project: Between projects
Favorite Gaming Platforms: PS1/2/3/P, NES, Wii, Genesis, Dreamcast, GBA, DS
Programming Language of Choice: C++

Re: SDL Motion/Visual studio?

Post 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...
Post Reply