Turn on/off lights in BGE?

hi, how can i turn on/off lights in bge by clicking the left mouse? is there any script or tutorial? thanks in advance for the answers! :slight_smile:

Set the energy of a lamp to 0.

import bge
scene = bge.logic.getCurrentScene()

lamp = scene.lights["name of the light"]
lamp.enegy = 0.0 #Some value

Also, you can make an animation in which you set the energy value:

Detect the mouse click with two mouse sensors:

mouse over + mouse left click

combine them with and controller

set the lamp visibility through a Visibility actuator

1 Like

You can even animate this with a light action (energy keyframes). To set a keyframe you navigate to the according frame e.g. 0 hold mouse cursor over the energy field (e.g. containing 1.0). Then press <i>. Do the same at frame 5 and energie 0.0.

Now you can play this action with an action actuator.

To create a switch you need a bit more logic at the lamp:

Property: [on] [Boolean]

Logic to change the light:
PropertySensor [Equal] Property: [on] Value:[False]
—> AND --> ActionActuator [Flipper] [LampAction] Start:[0] End:[5]

Logic of a switch:
KeyboardSensor [<space>]
—> AND --> PropertyActutuator [Toggle] Property: [on]

can use in loop animation mode?

I try create a flicekring or blinking light effect in BGE using F-curves --> noise Animation, and got a black horizontal lines not good see my video.Anybody can help me for solve this? thanks

Where? I do not see black lines.

If you really are getting black lines, then go see if there are newer drivers for your graphics card.

my problem is Vsync i discover working with Vsync disable causing this bad effect but how can enable vsync just for a moment player small distance from light?


render.VSYNC_ON # OFF or ADAPTIVE

Not sure if this works during runtime, but i bet it’s just you who get black lines, due to your pc/laptop can’t handle complex things or the load just get’s to much for graphic card.

i tryng enable disable vsync by player distance from light but not working may need create small cube in light position and work with near sensor?

please, for love of all things good, dont mess with vsync ingame. just dont.

my guess is tearing, which is what you get when you dont use vsync. alot of people like vync for this reason.

see if you can create a simple blend showing the black lines and post it here.

EDIT:
just watched the video, couldnt see anything odd. but you really need to tune down that effect ALOT or have a clear sezuire warning.

dont make the light blink so fast and dont go to pitch black.

only appear in my monitor cause is a lcd old tv understand. and beleive you can enable disable vsync in run time BGE 2.76. By default is OFF in my project.but i wish in my open world when all scene is darkness causa have a day/night cycle then i player camera near 40.00 from light then enable vsync and all things go slow to 60FPS (light animation work perfect) now if player camera out of 40.00 distance near from light then set back Vsync OFF and light i cant see more black horizontal lines.This is ocurring in just my monitor.The bad effect

all i would do at this point is post a “known issue” saying turn on vsync if you dont want to see artifacts. but never mess with a gamers system settings.

thats why we even have settings, to let the gamer decide whats important.

look in FPS you wish a speed speed and speed beleive me i play FPS since 20 years ago :grinning:

I got solution in my conteiners have 4 points to enter i go put sensors if play enter area Enable Vsync its a slow contamination area :cold_face::crazy_face:

if player out of conteiners Disable Vsync and game go fast again

just look now got a good effect using same lamp in my 3 levels of game very nice in 3th level got a sillent hill effect

I find solution for vsync ON decreasing all my animations!

I just calculate TicRate the default is 60.00 with vsync OFF in my project i find value 18.00 for got igual animation speed and all with vsybc ON, incredible if you setVsync_ON and back TicRate to default or > value of 60.00 you get Slow Motion effect in BGE < 2.77 cause they dont have setTimeScale() :jack_o_lantern:

I find solution for vsync ON decreasing all my animations!

I just calculate TicRate the default is 60.00 with vsync OFF in my project i find value 18.00 for got igual animation speed and all with vsybc ON, incredible if you setVsync_ON and back TicRate to default or > value of 60.00 you get Slow Motion effect in BGE < 2.77 cause they dont have setTimeScale() :jack_o_lantern: :jack_o_lantern: . The Game Killing Floor 2 made with udk engine have this in mode random shoot.when you shot i think generate a ramdom number 1 to 10 example and if ramdom number = specific number then Slow Motion effect is UP all animation go to slow…