📅  最后修改于: 2020-10-14 01:44:57             🧑  作者: Mango
此效果通过点光源使节点变亮。点光源是光在所有方向上衰减的光源。光源的强度取决于光源和节点之间的距离。类javafx.scene.effect.Light.Spot表示此效果。我们只需要实例化此类即可在节点上生成适当的光。
下表描述了该类的属性以及setter方法。
Property | Description | Setter Methods |
---|---|---|
pointsAtX | This is a double type property. It represents the X coordinate of the direction vector of light | setPointsAtX(double value) |
pointsAtY | This is a double type property. It represents the Y coordinate of the direction vector of light | setPointsAtY(double value) |
pointsAtZ | This is a double type property. It represents the Z coordinate of the direction vector of light. | setPointsAtZ(double value) |
specularExponent | This is a double type property. It represents the specularexponent. This is used to alter the focus of the light source. | setSpecularExponent(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.scene.shape.Rectangle;
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, 35));
text.setX(20);
text.setY(50);
text.setTextOrigin(VPos.TOP);
text.setText("Welcome to JavaTpoint");
text.setFill(Color.RED);
Light.Spot light = new Light.Spot();
light.setPointsAtX(0);
light.setPointsAtY(0);
light.setPointsAtZ(-50);
light.setSpecularExponent(5);
Lighting lighting = new Lighting();
text.setEffect(lighting);
Group root = new Group();
root.getChildren().add(text);
Scene scene = new Scene(root, 500, 200);
stage.setTitle("light.Spot example");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}