4
$\begingroup$

I am creating an options menu for a simple game. I want to make a button that will adjust my lamps energy up or down.

I would like both ways, a button that adjust the lamp energy up and a way to adjust it down.

$\endgroup$

2 Answers 2

4
$\begingroup$
scene = bge.logic.getCurrentScene()
cont = bge.logic.getCurrentController()
light = scene.lights['Lamp']

if cont.sensors['Mouse1'].hitObject.name == 'button.up' and cont.sensors['Lclick'].getButtonStatus(bge.events.LEFTMOUSE) == bge.logic.KX_INPUT_JUST_ACTIVATED:
    light.energy += 0.5

if cont.sensors['Mouse1'].hitObject.name == 'button.down' and cont.sensors['Lclick'].getButtonStatus(bge.events.LEFTMOUSE) == bge.logic.KX_INPUT_JUST_ACTIVATED:
    light.energy -= 0.5

Attach this script to your two buttons with these logic bricks. The two buttons must be named button.down and button.up, or you will have to change the names in the script.
logic bricks

The two buttons will increase and decrease the default Lamp energy by 0.5 per click.

$\endgroup$
0
4
$\begingroup$

The "I'm not a programmer!" approach.

First step: Create the button(s), create the light.

Second Step: Create an animation for the lamp where it is dim at frame 1 and bright at frame 200.

Third Step: Switch to game logic and add a property to the light named Bright. Make an action actuator with the play mode set to property set the property and the frame property of the actuator to be Bright. Do the rest of the setup as follows.

Logic setup

This basically means If the mouse is over the button (cube) and the mouse is clicked, add two to the Bright property. Play the PointAction as Bright is increased.

Forth step: (optional) Add an always sensor and a mouse visibility if your game has no way of knowing where the mouse is. Create another button with the exact same setup except make the property Bright decrease by two under the property actuator

$\endgroup$
2
  • 1
    $\begingroup$ I didn't even know that you could have animated lamps playing in the BGE! (jeep's headlights will be toggling on/off very soon.) $\endgroup$ Commented Jul 13, 2015 at 20:37
  • 2
    $\begingroup$ Learned a trick or 2 from BRSky $\endgroup$
    – ruckus
    Commented Jul 13, 2015 at 21:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .