Class AnimationRenderer
java.lang.Object
com.imyeyu.fx.utils.AnimationRenderer
动画帧渲染器,可控帧率,在 JVM 启动参数含-Djavafx.animation.fullspeed=true时,预设 FPS
才可以突破屏幕刷新率。
Box box = new Box(128, 128, 128);
box.setDrawMode(DrawMode.LINE);
box.setCullFace(CullFace.BACK);
box.setMaterial(new PhongMaterial(RED));
box.setRotationAxis(new Point3D(0, 64, 0));
// 以 240 FPS 每秒 90 度旋转一个 3D 立方体
AnimationRenderer renderer = new AnimationRenderer(240);
renderer.addRenderCallback(deltaSecond -> {
box.setRotate(box.getRotate() + 90 * deltaSecond);
});
- Since:
- 2023-03-08 09:48
- Author:
- 夜雨
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class一次性动画static interface一次性动画回调 -
Property Summary
Properties -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final LinkedList<AnimationRenderer.Animation> 动画渲染队列protected final javafx.beans.property.IntegerProperty平均帧率protected final javafx.beans.property.DoubleProperty平均帧生成时间protected final LinkedList<com.imyeyu.java.bean.CallbackArg<Double>> 渲染回调protected final RunAsyncScheduled<?> 状态计时器protected final javafx.animation.AnimationTimer渲染器 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRenderCallback(com.imyeyu.java.bean.CallbackArg<Double> callback) 添加渲染回调double获取累计帧差(毫秒)double获取累计帧差(纳秒)double获取累计帧差(秒)javafx.beans.property.ReadOnlyIntegerProperty获取当前渲染 FPS 属性intgetFPS()获取当前渲染 FPSdoublegetMPF()获取帧生成时间(毫秒)int预设 FPSdoublemillis()javafx.beans.property.ReadOnlyDoubleProperty获取帧生成时间属性(毫秒)doublenanos()voidremoveRenderCallback(com.imyeyu.java.bean.CallbackArg<Double> callback) 移除渲染回调voidrender(javafx.util.Duration duration, AnimationRenderer.AnimationCallback callback) 添加渲染动画voidrender(javafx.util.Duration duration, AnimationRenderer.AnimationCallback callback, com.imyeyu.java.bean.Callback onFinishedEvent) 添加渲染动画doublesecond()voidsetPrefFPS(int prefFPS) 预设 FPS,渲染器会尽量匹配此帧率渲染,可能会突破少许,系统资源紧张时实际渲染帧率会低于预设voidstart()启动voidstop()停止
-
Property Details
-
mpf
public javafx.beans.property.ReadOnlyDoubleProperty mpfProperty获取帧生成时间属性(毫秒)- See Also:
-
fps
public javafx.beans.property.ReadOnlyIntegerProperty fpsProperty获取当前渲染 FPS 属性- See Also:
-
-
Field Details
-
renderCallbacks
渲染回调 -
animations
动画渲染队列 -
timer
protected final javafx.animation.AnimationTimer timer渲染器 -
mpf
protected final javafx.beans.property.DoubleProperty mpf平均帧生成时间 -
fps
protected final javafx.beans.property.IntegerProperty fps平均帧率 -
statusTimer
状态计时器
-
-
Constructor Details
-
AnimationRenderer
public AnimationRenderer()默认构造,60 FPS -
AnimationRenderer
public AnimationRenderer(int prefFPS) 标准构造- Parameters:
prefFPS- 预设帧率
-
-
Method Details
-
start
public void start()启动 -
stop
public void stop()停止 -
render
添加渲染动画- Parameters:
duration- 持续时间callback- 动画回调
-
render
public void render(javafx.util.Duration duration, AnimationRenderer.AnimationCallback callback, com.imyeyu.java.bean.Callback onFinishedEvent) 添加渲染动画- Parameters:
duration- 持续时间callback- 动画回调onFinishedEvent- 动画完成回调
-
addRenderCallback
添加渲染回调- Parameters:
callback- 回调
-
removeRenderCallback
移除渲染回调- Parameters:
callback- 回调
-
setPrefFPS
public void setPrefFPS(int prefFPS) 预设 FPS,渲染器会尽量匹配此帧率渲染,可能会突破少许,系统资源紧张时实际渲染帧率会低于预设- Parameters:
prefFPS- FPS 取值范围 [1, 1000]
-
getMPF
public double getMPF()获取帧生成时间(毫秒)- Returns:
- 帧生成时间
-
mpfProperty
public javafx.beans.property.ReadOnlyDoubleProperty mpfProperty()获取帧生成时间属性(毫秒)- Returns:
- 帧生成时间属性(毫秒)
-
getFPS
public int getFPS()获取当前渲染 FPS- Returns:
- FPS
-
fpsProperty
public javafx.beans.property.ReadOnlyIntegerProperty fpsProperty()获取当前渲染 FPS 属性- Returns:
- FPS 属性
-
deltaNanos
public double deltaNanos()获取累计帧差(纳秒)- Returns:
- 累计帧差(纳秒)
-
deltaMillis
public double deltaMillis()获取累计帧差(毫秒)- Returns:
- 累计帧差(毫秒)
-
deltaSecond
public double deltaSecond()获取累计帧差(秒)- Returns:
- 累计帧差(秒)
-
nanos
public double nanos()- Returns:
- 当前帧(纳秒)
-
millis
public double millis()- Returns:
- 当前帧(毫秒)
-
second
public double second()- Returns:
- 当前帧(秒)
-
getPrefFPS
public int getPrefFPS()预设 FPS
-