📅  最后修改于: 2020-10-14 01:45:55             🧑  作者: Mango
在这种照明效果下,将光源在3D空间中指定位置。顾名思义,光源位于某个点,并且将节点缝合以从该特定光源变亮。类javafx.scene.effect.Light.Point表示此光源。我们需要实例化此类,以便在节点上生成适当的光照。
下表描述了类的属性及其设置方法。
Property | Description | Setter Methods |
---|---|---|
X | It is a double type property. It represents the X coordinate of the Light source. | setX(Double value) |
Y | It is a double type property. It represents the Y Coordinate of the light source. | setY(Double value) |
Z | It is a double type property. It represents the Z coordinate of the light source. | setZ(Double value) |
该类包含两个构造函数
package application;
import javafx.application.Application;
import javafx.geometry.VPos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.Light;
import javafx.scene.effect.Lighting;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
public class LightingExample1 extends Application {
@Override
public void start(Stage stage) {
Text text = new Text();
text.setFont(Font.font(null, FontWeight.BOLD, 40));
text.setX(50);
text.setY(40);
text.setTextOrigin(VPos.TOP);
text.setText("HELLO WORLD!!");
text.setFill(Color.RED);
Light.Point light = new Light.Point();
light.setX(0);
light.setY(0);
light.setZ(-100);
Lighting lighting = new Lighting();
lighting.setSurfaceScale(5);
text.setEffect(lighting);
Group root = new Group();
root.getChildren().add(text);
Scene scene = new Scene(root, 500, 200);
stage.setTitle("light.Point example");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}