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

JavaFX Light Distant效果

点击下载

本文概述

这样, 该节点从远处的光源变亮。远处的光源是与物体保持一定距离的光源, 并且光从光源到物体在一个方向上衰减。在JavaFX中, 类javafx.scene.effect.Light.Distant表示Distant光源。我们需要实例化此类以在节点上生成适当的光。

属性

该类包含下表中描述的两个属性。

属性 描述 设置方法
azimuth 此属性的类型为double, 它表示光的方位角。 setAzimuth(double value)
elevation 此属性是double类型的, 它表示灯光的高程。 setAlivation(double value)

构建器

该类包含两个构造函数

  1. public Light.Distant():使用默认参数创建类的新实例。
  2. public Light.Distant(双方位角, 双标高, 彩色):使用指定的参数创建类的新实例。

例:

package application;
import javafx.application.Application; 
import javafx.scene.Group; 
import javafx.scene.Scene;
import javafx.scene.effect.Light;
import javafx.scene.effect.Lighting;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
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, 35));        
text.setX(60); 
text.setY(100); 
text.setText("Welcome to srcmini");        
text.setFill(Color.GREEN);   
Image img = new Image("https://www.srcmini02.com/operating-system/images/operating-system-tutorial.png");
ImageView imgview = new ImageView(img);
imgview.setX(150);
imgview.setY(200);
Light.Distant light = new Light.Distant();
light.setAzimuth(0.2);
light.setColor(Color.YELLOW);
Lighting lighting = new Lighting(); 
lighting.setLight(light);
text.setEffect(lighting);       
imgview.setEffect(lighting); 
Group root = new Group(text, imgview);   
Scene scene = new Scene(root, 580, 420);  
stage.setTitle("light.Distant example");  
stage.setScene(scene);
stage.show();         
} 
public static void main(String args[]){ 
launch(args); 
} 
}
JavaFX Light Distant的效果
赞(0)
未经允许不得转载:srcmini » JavaFX Light Distant效果

相关推荐

评论 抢沙发

评论前必须登录!