Problem with setVisible *ILightSceneNode*

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
wildrj
Posts: 301
Joined: Thu Mar 23, 2006 12:49 am
Location: Texas/ Cyberspace
Contact:

Problem with setVisible *ILightSceneNode*

Post by wildrj »

I have for some reason a problem turning on and off a light using setVisible() i can go from on to off but not off to on not sure if anyone else has this problem simple code im using is below.

Code: Select all

smgr->getSceneNodeFromName("sl_Light1")->setVisible(on_light);
on_light is just a bool that is turned on and off from a key event.[/code]
http://wild.deathtouchstudios.com << My gamedev blog
<Programming is a way of life>
If at first you don't succeed press the delete key till you do :)
cobra
Posts: 371
Joined: Fri Jan 23, 2009 2:56 am
Location: United States
Contact:

Post by cobra »

Could you show your event handling code? I've never tried it, but you should be able to set a light scene node to invisible.

I think maybe you're handling events for turning it off wrongly.
Josiah Hartzell
Image
wildrj
Posts: 301
Joined: Thu Mar 23, 2006 12:49 am
Location: Texas/ Cyberspace
Contact:

Post by wildrj »

like i said im just switching on and hoff the bool value :/

Code: Select all

	if(eventReceiver->keyDown('H'))
	{
		if(on_light == true)
                  on_light = false;
                if(on_light == false)
                  on_light = true;

	}
}
http://wild.deathtouchstudios.com << My gamedev blog
<Programming is a way of life>
If at first you don't succeed press the delete key till you do :)
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

smgr->getSceneNodeFromName("sl_Light1")->setVisible(on_light);

when do u call this?
every frame?
if not then maybe this line never occour...
debug it if it occours, and the on_light has the right value

if its all ok, then try to set the visibility of the light to false when creating, and check if it disappears.
if it works as expected, then there is something wrong in your code
Image
Image
wildrj
Posts: 301
Joined: Thu Mar 23, 2006 12:49 am
Location: Texas/ Cyberspace
Contact:

Post by wildrj »

line of code is called every frame. as well has if i set it false on start up it disappears. but cant switch it on.
http://wild.deathtouchstudios.com << My gamedev blog
<Programming is a way of life>
If at first you don't succeed press the delete key till you do :)
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

wildrj wrote:like i said im just switching on and hoff the bool value :/

Code: Select all

	if(eventReceiver->keyDown('H'))
	{
		if(on_light == true)
                  on_light = false;
                if(on_light == false)
                  on_light = true;

	}
}
you need to see if this is a keypress or not. you are likly toggling the light two times each time the key is pressed. once for down, and then once for up so it looks like it isnt working.

Code: Select all

	virtual bool OnEvent(const SEvent& e)
	{
		switch (e.EventType)
		{
			case EET_KEY_INPUT_EVENT : 
				{
					if (e.KeyInput.PressedDown == true)
					{
						if(eventReceiver->keyDown('H')) 
   { 
      if(on_light == true) 
                  on_light = false; 
                if(on_light == false) 
                  on_light = true; 

   } 

Katsankat
Posts: 178
Joined: Sun Mar 12, 2006 4:15 am
Contact:

Post by Katsankat »

:roll: Replace your bad indented junk with

Code: Select all

on_light = !on_light;
http://www.cplusplus.com/doc/tutorial/control/
Hirte
Posts: 73
Joined: Sat Apr 01, 2006 1:32 pm

Post by Hirte »

Just to explain it:

if(on_light == true)
on_light = false;

If your on_light is true, you switch it to false.
In the next line you check if it is false, which it is, so you switch it back;)

if(on_light == false)
on_light = true;
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

Hirte wrote:Just to explain it:

if(on_light == true)
on_light = false;

If your on_light is true, you switch it to false.
In the next line you check if it is false, which it is, so you switch it back;)

if(on_light == false)
on_light = true;
nice catch. cant believe we didnt see that :)
Post Reply