Help with Sprites

Posts 14 of 4 · Page 1 of 1
Help with Sprites
I loaded two sprites:

MainMenu and Battle

I then display it like this:
Code:
void MainMenu(void)
{
    mainmenu->Draw(mainmenusprite, NULL, &center, &position, D3DCOLOR_XRGB(255, 255, 255));
	if(GetAsyncKeyState(VK_ESCAPE))
	{
		mainmenu->Draw(battlesprite, NULL, &center, &position, D3DCOLOR_XRGB(255, 255, 255));	
	}
	if(GetAsyncKeyState(VK_INSERT))
	{
		mainmenu->Draw(mainmenusprite, NULL, &center, &position, D3DCOLOR_XRGB(255, 255, 255));	
	}
}
When I press those buttons though, the sprite only stays there when I hold the button. How do I make it stay there permanently even if I let go of the key?
To answer your question: You would have a boolean (or have game states) that would store the "show this sprite" value. Every time the key is pressed you would flip the value. When the value is true, display the sprites.

A recommendation: Don't use GetAsyncKeyState in any actual applications. It's very unreliable and "polling" is not recommended by Microsoft. Handle WM_KEYDOWN and WM_KEYUP to do the dirty work of input.
Quote Originally Posted by mmbob View Post
To answer your question: You would have a boolean (or have game states) that would store the "show this sprite" value. Every time the key is pressed you would flip the value. When the value is true, display the sprites.

A recommendation: Don't use GetAsyncKeyState in any actual applications. It's very unreliable and "polling" is not recommended by Microsoft. Handle WM_KEYDOWN and WM_KEYUP to do the dirty work of input.
This is true, if I used GAKS and the game wasn't the active window and I pressed left or right arrow the sprite would change anyway.
Thanks I fixed it now.
Posts 14 of 4 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Need help?