Skip to main content
GameDev.net gamedev.net
🔒 Locked

Lighting

Started by Newbie00 May 18, 2003 at 2:14 PM 1 replies 250+ views
Original Post
Newbie00
Newbie00
I am trying to create something so when the key Number Pad 9 is hit red light will be added to the player models.
if(GetAsyncKeyState(0x69)){
	f_pDirect3DDevice->SetLight( 0, &Light );
	f_pDirect3DDevice->LightEnable( 0, true );
}
 
The light shows fine on the player as long as I hold down the key. How would I make it so that I would not have to hold down the key to get the right light to stay on?
strahan
strahan
Do this:

// global or class declaration
BOOL g_bKeypad9Pressed = FALSE;

// Somewhere in initializing code
f_pDirect3DDevice->SetLight( 0, &Light );

void YourGameLoop(void)
{
    if(GetAsyncKeyState(0x69))
     {
         // Toggle pressed state
         g_bKeypad9Pressed = !g_bKeypad9Pressed;
         f_pDirect3DDevice->LightEnable( 0, g_bKeypad9Pressed );
     }
}


[edited by - strahan on May 18, 2003 3:27:17 PM]
Newbie00
Newbie00
Thanks for the reply but it still will only stay on if I hold down the key.

Edit:

Fix it by putting


if(g_bKP9P){
f_pDirect3DDevice->SetLight( 0, &Light );
f_pDirect3DDevice->LightEnable( 0, true );
}


In the SetLight function.

[edited by - Newbie00 on May 18, 2003 7:32:32 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.