Skip to main content
Commonmark migration
Source Link

First you have to enable Object Color, that is found in the Properties window, Material tab, then under the Options region Object Color.
One quirk I found, be sure that the diffuse color of the material is pure white [1, 1, 1]. If it is not you will only be able to control the color up to that level. Example: say the material's color is red [1, 0, 0], now because the green and blue channels are 0 you will never be able to get any value in those channels.
Now the material will use the object's color, that color is found under Properties > Object > Display > Object Color*.

To change the object color while the game is running use this bit of python.

cont = bge.logic.getCurrentController() obj = cont.owner # set the game object's color obj.color = [ 0.0, 0.0, 0.0, 1.0] 

The color method is looking for a vector in the form of [Red, Green, Blue, Alpha], (You can just leave the alpha set to 1, I have yet to find a place where it is used.)

The game UI for changing the color##color

Creating the interface is the most complicated part.
Here is a working demo file with three sliders, one each for red green and blue. The three sliders all have a game property one for each color channel. They also have these logic bricks. The only difference among the three is the property name. logic bricks

This script is what takes the input from the logic bricks above, and changes the three values.

scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() own = cont.owner if cont.sensors['Mouse'].getButtonStatus(bge.events.LEFTMOUSE) == bge.logic.KX_INPUT_ACTIVE: posZ = cont.sensors['Mouse1'].hitPosition[2] if posZ > 1.0: posZ = 1 elif posZ < 0: posZ = 0 own.worldPosition.z = posZ prop = cont.actuators["prop"] prop.value = str(own.worldPosition.z) cont.activate(prop) 

Then another script on the object you want to change the color is this script. A always sensor set to True pulse mode makes the script run constantly.

scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() own = cont.owner r = scene.objects['handle']['r'] g = scene.objects['handle.g']['g'] b = scene.objects['handle.b']['b'] own.color = [ r, g, b, 1.0] 

First you have to enable Object Color, that is found in the Properties window, Material tab, then under the Options region Object Color.
One quirk I found, be sure that the diffuse color of the material is pure white [1, 1, 1]. If it is not you will only be able to control the color up to that level. Example: say the material's color is red [1, 0, 0], now because the green and blue channels are 0 you will never be able to get any value in those channels.
Now the material will use the object's color, that color is found under Properties > Object > Display > Object Color*.

To change the object color while the game is running use this bit of python.

cont = bge.logic.getCurrentController() obj = cont.owner # set the game object's color obj.color = [ 0.0, 0.0, 0.0, 1.0] 

The color method is looking for a vector in the form of [Red, Green, Blue, Alpha], (You can just leave the alpha set to 1, I have yet to find a place where it is used.)

The game UI for changing the color##

Creating the interface is the most complicated part.
Here is a working demo file with three sliders, one each for red green and blue. The three sliders all have a game property one for each color channel. They also have these logic bricks. The only difference among the three is the property name. logic bricks

This script is what takes the input from the logic bricks above, and changes the three values.

scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() own = cont.owner if cont.sensors['Mouse'].getButtonStatus(bge.events.LEFTMOUSE) == bge.logic.KX_INPUT_ACTIVE: posZ = cont.sensors['Mouse1'].hitPosition[2] if posZ > 1.0: posZ = 1 elif posZ < 0: posZ = 0 own.worldPosition.z = posZ prop = cont.actuators["prop"] prop.value = str(own.worldPosition.z) cont.activate(prop) 

Then another script on the object you want to change the color is this script. A always sensor set to True pulse mode makes the script run constantly.

scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() own = cont.owner r = scene.objects['handle']['r'] g = scene.objects['handle.g']['g'] b = scene.objects['handle.b']['b'] own.color = [ r, g, b, 1.0] 

First you have to enable Object Color, that is found in the Properties window, Material tab, then under the Options region Object Color.
One quirk I found, be sure that the diffuse color of the material is pure white [1, 1, 1]. If it is not you will only be able to control the color up to that level. Example: say the material's color is red [1, 0, 0], now because the green and blue channels are 0 you will never be able to get any value in those channels.
Now the material will use the object's color, that color is found under Properties > Object > Display > Object Color*.

To change the object color while the game is running use this bit of python.

cont = bge.logic.getCurrentController() obj = cont.owner # set the game object's color obj.color = [ 0.0, 0.0, 0.0, 1.0] 

The color method is looking for a vector in the form of [Red, Green, Blue, Alpha], (You can just leave the alpha set to 1, I have yet to find a place where it is used.)

The game UI for changing the color

Creating the interface is the most complicated part.
Here is a working demo file with three sliders, one each for red green and blue. The three sliders all have a game property one for each color channel. They also have these logic bricks. The only difference among the three is the property name. logic bricks

This script is what takes the input from the logic bricks above, and changes the three values.

scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() own = cont.owner if cont.sensors['Mouse'].getButtonStatus(bge.events.LEFTMOUSE) == bge.logic.KX_INPUT_ACTIVE: posZ = cont.sensors['Mouse1'].hitPosition[2] if posZ > 1.0: posZ = 1 elif posZ < 0: posZ = 0 own.worldPosition.z = posZ prop = cont.actuators["prop"] prop.value = str(own.worldPosition.z) cont.activate(prop) 

Then another script on the object you want to change the color is this script. A always sensor set to True pulse mode makes the script run constantly.

scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() own = cont.owner r = scene.objects['handle']['r'] g = scene.objects['handle.g']['g'] b = scene.objects['handle.b']['b'] own.color = [ r, g, b, 1.0] 
small bit I forgot, something changed between 2.72 and 2.78 in how obj color works in game
Source Link
David
  • 50.1k
  • 40
  • 164
  • 324

First you have to enable Object Color, that is found in the Properties window, Material tab, then under the Options region Object Color.
One quirk I found, be sure that the diffuse color of the material is pure white [1, 1, 1]. If it is not you will only be able to control the color up to that level. Example: say the material's color is red [1, 0, 0], now because the green and blue channels are 0 you will never be able to get any value in those channels.
Now the material will use the object's color, that color is found under Properties > Object > Display > Object Color*.

To change the object color while the game is running use this bit of python.

cont = bge.logic.getCurrentController() obj = cont.owner # set the game object's color obj.color = [ 0.0, 0.0, 0.0, 1.0] 

The color method is looking for a vector in the form of [Red, Green, Blue, Alpha], (You can just leave the alpha set to 1, I have yet to find a place where it is used.)

The game UI for changing the color##

Creating the interface is the most complicated part.
Here is a working demo file with three sliders, one each for red green and blue. The three sliders all have a game property one for each color channel. They also have these logic bricks. The only difference among the three is the property name. logic bricks

This script is what takes the input from the logic bricks above, and changes the three values.

scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() own = cont.owner if cont.sensors['Mouse'].getButtonStatus(bge.events.LEFTMOUSE) == bge.logic.KX_INPUT_ACTIVE: posZ = cont.sensors['Mouse1'].hitPosition[2] if posZ > 1.0: posZ = 1 elif posZ < 0: posZ = 0 own.worldPosition.z = posZ prop = cont.actuators["prop"] prop.value = str(own.worldPosition.z) cont.activate(prop) 

Then another script on the object you want to change the color is this script. A always sensor set to True pulse mode makes the script run constantly.

scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() own = cont.owner r = scene.objects['handle']['r'] g = scene.objects['handle.g']['g'] b = scene.objects['handle.b']['b'] own.color = [ r, g, b, 1.0] 

First you have to enable Object Color, that is found in the Properties window, Material tab, then under the Options region Object Color.
Now the material will use the object's color, that color is found under Properties > Object > Display > Object Color*.

To change the object color while the game is running use this bit of python.

cont = bge.logic.getCurrentController() obj = cont.owner # set the game object's color obj.color = [ 0.0, 0.0, 0.0, 1.0] 

The color method is looking for a vector in the form of [Red, Green, Blue, Alpha], (You can just leave the alpha set to 1, I have yet to find a place where it is used.)

The game UI for changing the color##

Creating the interface is the most complicated part.
Here is a working demo file with three sliders, one each for red green and blue. The three sliders all have a game property one for each color channel. They also have these logic bricks. The only difference among the three is the property name. logic bricks

This script is what takes the input from the logic bricks above, and changes the three values.

scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() own = cont.owner if cont.sensors['Mouse'].getButtonStatus(bge.events.LEFTMOUSE) == bge.logic.KX_INPUT_ACTIVE: posZ = cont.sensors['Mouse1'].hitPosition[2] if posZ > 1.0: posZ = 1 elif posZ < 0: posZ = 0 own.worldPosition.z = posZ prop = cont.actuators["prop"] prop.value = str(own.worldPosition.z) cont.activate(prop) 

Then another script on the object you want to change the color is this script. A always sensor set to True pulse mode makes the script run constantly.

scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() own = cont.owner r = scene.objects['handle']['r'] g = scene.objects['handle.g']['g'] b = scene.objects['handle.b']['b'] own.color = [ r, g, b, 1.0] 

First you have to enable Object Color, that is found in the Properties window, Material tab, then under the Options region Object Color.
One quirk I found, be sure that the diffuse color of the material is pure white [1, 1, 1]. If it is not you will only be able to control the color up to that level. Example: say the material's color is red [1, 0, 0], now because the green and blue channels are 0 you will never be able to get any value in those channels.
Now the material will use the object's color, that color is found under Properties > Object > Display > Object Color*.

To change the object color while the game is running use this bit of python.

cont = bge.logic.getCurrentController() obj = cont.owner # set the game object's color obj.color = [ 0.0, 0.0, 0.0, 1.0] 

The color method is looking for a vector in the form of [Red, Green, Blue, Alpha], (You can just leave the alpha set to 1, I have yet to find a place where it is used.)

The game UI for changing the color##

Creating the interface is the most complicated part.
Here is a working demo file with three sliders, one each for red green and blue. The three sliders all have a game property one for each color channel. They also have these logic bricks. The only difference among the three is the property name. logic bricks

This script is what takes the input from the logic bricks above, and changes the three values.

scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() own = cont.owner if cont.sensors['Mouse'].getButtonStatus(bge.events.LEFTMOUSE) == bge.logic.KX_INPUT_ACTIVE: posZ = cont.sensors['Mouse1'].hitPosition[2] if posZ > 1.0: posZ = 1 elif posZ < 0: posZ = 0 own.worldPosition.z = posZ prop = cont.actuators["prop"] prop.value = str(own.worldPosition.z) cont.activate(prop) 

Then another script on the object you want to change the color is this script. A always sensor set to True pulse mode makes the script run constantly.

scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() own = cont.owner r = scene.objects['handle']['r'] g = scene.objects['handle.g']['g'] b = scene.objects['handle.b']['b'] own.color = [ r, g, b, 1.0] 
paste all. nough said
Source Link
David
  • 50.1k
  • 40
  • 164
  • 324

First you have to enable Object ColorObject Color, that is found in the Properties >window, Material >tab, then under the Options >region Object Color. Now
Now the material will use the object's color, that color is found under Properties > Object > Display > Object Color*.

To change the object color while the game is running use this bit of python.

cont = bge.logic.getCurrentController() obj = cont.owner # set the game object's color obj.color = [ 0.0, 0.0, 0.0, 1.0] 

The colorcolor method is looking for a vector in the form of [Red, Green, Blue, Alpha], (You can just leave the alpha set to 1, I have yet to find a place where it is used.)

The game UI for changing the color##

Creating the interface is the most complicated part.
HereHere is a working demo file with three sliders, one each for red green and blue. The three sliders all have a game property one for each color channel. They also have these logic bricks. The only difference among the three is the property name. logic bricks

This script is what takes the input from the logic bricks above, and changes the three values.

scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() own = cont.owner if cont.sensors['Mouse'].getButtonStatus(bge.events.LEFTMOUSE) == bge.logic.KX_INPUT_ACTIVE: posZ = cont.sensors['Mouse1'].hitPosition[2] if posZ > 1.0: posZ = 1 elif posZ < 0: posZ = 0 own.worldPosition.z = posZ prop = cont.actuators["prop"] prop.value = str(own.worldPosition.z) cont.activate(prop) 

Then another script on the object you want to change the color is this script. A always sensor set to True pulse mode makes the script run constantly.

scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() own = cont.owner r = scene.objects['handle']['r'] g = scene.objects['handle.g']['g'] b = scene.objects['handle.b']['b'] own.color = [ r, g, b, 1.0] 

First you have to enable Object Color, Properties > Material > Options > Object Color. Now the material will use the object's color, that color is found under Properties > Object > Display > Object Color*.

To change the object color while the game is running use this bit of python.

cont = bge.logic.getCurrentController() obj = cont.owner # set the game object's color obj.color = [ 0.0, 0.0, 0.0, 1.0] 

The color method is looking for a vector in the form of [Red, Green, Blue, Alpha], (You can just leave the alpha set to 1, I have yet to find a place where it is used.)

The UI for changing the color##

Creating the interface is the most complicated part.
Here is a working demo file with three sliders, one each for red green and blue. The three sliders all have a game property one for each color channel. They also have these logic bricks. The only difference among the three is the property name. logic bricks

This script is what takes the input from the logic bricks above, and changes the three values.

scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() own = cont.owner if cont.sensors['Mouse'].getButtonStatus(bge.events.LEFTMOUSE) == bge.logic.KX_INPUT_ACTIVE: posZ = cont.sensors['Mouse1'].hitPosition[2] if posZ > 1.0: posZ = 1 elif posZ < 0: posZ = 0 own.worldPosition.z = posZ prop = cont.actuators["prop"] prop.value = str(own.worldPosition.z) cont.activate(prop) 

Then another script on the object you want to change the color is this script. A always sensor set to True pulse mode makes the script run constantly.

scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() own = cont.owner r = scene.objects['handle']['r'] g = scene.objects['handle.g']['g'] b = scene.objects['handle.b']['b'] own.color = [ r, g, b, 1.0] 

First you have to enable Object Color, that is found in the Properties window, Material tab, then under the Options region Object Color.
Now the material will use the object's color, that color is found under Properties > Object > Display > Object Color*.

To change the object color while the game is running use this bit of python.

cont = bge.logic.getCurrentController() obj = cont.owner # set the game object's color obj.color = [ 0.0, 0.0, 0.0, 1.0] 

The color method is looking for a vector in the form of [Red, Green, Blue, Alpha], (You can just leave the alpha set to 1, I have yet to find a place where it is used.)

The game UI for changing the color##

Creating the interface is the most complicated part.
Here is a working demo file with three sliders, one each for red green and blue. The three sliders all have a game property one for each color channel. They also have these logic bricks. The only difference among the three is the property name. logic bricks

This script is what takes the input from the logic bricks above, and changes the three values.

scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() own = cont.owner if cont.sensors['Mouse'].getButtonStatus(bge.events.LEFTMOUSE) == bge.logic.KX_INPUT_ACTIVE: posZ = cont.sensors['Mouse1'].hitPosition[2] if posZ > 1.0: posZ = 1 elif posZ < 0: posZ = 0 own.worldPosition.z = posZ prop = cont.actuators["prop"] prop.value = str(own.worldPosition.z) cont.activate(prop) 

Then another script on the object you want to change the color is this script. A always sensor set to True pulse mode makes the script run constantly.

scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() own = cont.owner r = scene.objects['handle']['r'] g = scene.objects['handle.g']['g'] b = scene.objects['handle.b']['b'] own.color = [ r, g, b, 1.0] 
added 1240 characters in body
Source Link
David
  • 50.1k
  • 40
  • 164
  • 324
Loading
Source Link
David
  • 50.1k
  • 40
  • 164
  • 324
Loading