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.
wildrj
Posts: 301 Joined: Thu Mar 23, 2006 12:49 am
Location: Texas/ Cyberspace
Contact:
Post
by wildrj » Sat Jul 18, 2009 11:48 pm
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]
cobra
Posts: 371 Joined: Fri Jan 23, 2009 2:56 am
Location: United States
Contact:
Post
by cobra » Sun Jul 19, 2009 12:26 am
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
wildrj
Posts: 301 Joined: Thu Mar 23, 2006 12:49 am
Location: Texas/ Cyberspace
Contact:
Post
by wildrj » Sun Jul 19, 2009 2:02 am
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;
}
}
B@z
Posts: 876 Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary
Post
by B@z » Sun Jul 19, 2009 2:13 am
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
wildrj
Posts: 301 Joined: Thu Mar 23, 2006 12:49 am
Location: Texas/ Cyberspace
Contact:
Post
by wildrj » Sun Jul 19, 2009 2:43 am
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.
Seven
Posts: 1034 Joined: Mon Nov 14, 2005 2:03 pm
Post
by Seven » Sun Jul 19, 2009 2:59 am
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;
}
Hirte
Posts: 73 Joined: Sat Apr 01, 2006 1:32 pm
Post
by Hirte » Sun Jul 19, 2009 7:06 am
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 » Sun Jul 19, 2009 1:40 pm
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