个性化阅读
专注于IT技术分析

JavaFX Light.Spot效果

本文概述

此效果通过点光源使节点变亮。点光源是光在所有方向上衰减的光源。光源的强度取决于光源和节点之间的距离。类javafx.scene.effect.Light.Spot表示此效果。我们只需要实例化此类即可在节点上生成适当的光。

物产

下表描述了该类的属性以及setter方法。

属性 描述 设置方法
pointsAtX 这是一个双精度类型的属性。它代表光的方向向量的X坐标 setPointsAtX(double value)
pointsAtY 这是一个双精度类型的属性。它代表光的方向向量的Y坐标 setPointsAtY(double value)
pointsAtZ 这是一个双精度类型的属性。它表示光的方向向量的Z坐标。 setPointsAtZ(double value)
specularExponent 这是一个双精度类型的属性。它代表镜面反射指数。这用于更改光源的焦点。 setSpecularExponent(double value)

建设者

该类包含两个构造函数

  1. Light.Spot():使用默认参数创建一个新实例。
  2. Light.Spot(double x, double y, double z, double specularexponent, 颜色color):使用指定的参数创建一个新实例。

例:

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 srcmini");        
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); 
} 
}
JavaFX Light.Spot效果
赞(0)
未经允许不得转载:srcmini » JavaFX Light.Spot效果

相关推荐

评论 抢沙发

评论前必须登录!