Panda3D sets the game background color and node color, transparency

How to set game background color and node color in Panda3D

​ In the process of using panda3D to develop, I encountered many problems. There are too few resources on the domestic website, so I sorted out the time-consuming but simple problems I encountered as follows for the reference of subsequent developers.

1. Set the background color

self.setBackgroundColor(r=0.2549, g=0.41176, b=0.88235, a=0)

​ where self is ShowBase. The result of the above settings is shown in the image below (the bottom is the scene I loaded).

insert image description here

​ For the color r, g, b parameters, it is a floating point number between 0-1, not an integer between 0-255.

​ You can refer to this article for the color comparison table .

​ If you can't find the color you want, it's also very simple. Divide the value between 0-255 by 255 to get the floating point number you need.

2. Set node color

​ It is relatively simple to set the node color, the code is as follows:

myNodePath.setColor(R, G, B, A)

The use of parameters is the same as the background color.

​ If you want to clear the color, the code is as follows:

myNodePath.clearColor()

One thing to note is that although setColor can have a parameter to directly set the transparency, the direct setting will not take effect, and it needs to be declared first. The code is as follows:

myNodePath.setTransparency(TransparencyAttrib.MAlpha)
myNodePath.setColor(R, G, B, A)

The content of this article is over here, and this is also the problem I encountered during the development process. The content of this article is all organized by the blogger himself and summarized based on his own understanding. If there are any mistakes, please criticize and correct.

If this article can be helpful to you, please like, bookmark, follow, and give bloggers a wave.

Guess you like

Origin blog.csdn.net/qq_34666857/article/details/125479333