本文整理汇总了Java中javafx.animation.AnimationTimer类的典型用法代码示例。如果您正苦于以下问题:Java AnimationTimer类的具体用法?Java AnimationTimer怎么用?Java AnimationTimer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AnimationTimer类属于javafx.animation包,在下文中一共展示了AnimationTimer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import javafx.animation.AnimationTimer; //导入依赖的package包/类
@Override
public void start(Stage primaryStage) throws Exception {
// store the primary stage reference.
this.primaryStage = primaryStage;
// construct the context for the game.
context = new PongContext();
// set definitions for the primary stage.
primaryStage.setTitle("JavaFX - Pong");
primaryStage.setResizable(false);
primaryStage.show();
primaryStage.setScene(new WelcomeScene(this));
// construct and start a trivial main loop for 60fps simulation.
mainLoop = new AnimationTimer() {
@Override
public void handle(long now) {
Scene scene = primaryStage.getScene();
if (scene instanceof AbstractScene) {
((AbstractScene) scene).tick();
}
}
};
mainLoop.start();
}
示例2: FXGameLoop
import javafx.animation.AnimationTimer; //导入依赖的package包/类
public FXGameLoop(EventBus bus) {
this.bus = bus;
prevNanos = 0;
loopComponents = new ArrayList<>();
timer = new AnimationTimer() {
@Override
public void handle(long now) {
// calculate elapsed time
if (prevNanos == 0) {
prevNanos = now;
return;
}
long deltaNanos = now - prevNanos;
prevNanos = now;
double dt = deltaNanos / 1.0e9;
// updates for each game system
for (LoopComponent loopComponent : loopComponents) {
loopComponent.update(dt);
}
}
};
initHandlers();
}
示例3: start
import javafx.animation.AnimationTimer; //导入依赖的package包/类
@Override
public void start(Stage primaryStage) throws Exception {
System.out.println("Started");
Sequence s = new Sequence(new Wait(10f), new Print("Hello World!"));
LongValue lastNanoTime = new LongValue( System.nanoTime() );
new AnimationTimer() {
public void handle(long currentNanoTime) {
// calculate time since last update.
double elapsedTime = (currentNanoTime - lastNanoTime.value) / 1000000000.0;
lastNanoTime.value = currentNanoTime;
s.update((float) elapsedTime);
}
}.start();
}
示例4: Smoke
import javafx.animation.AnimationTimer; //导入依赖的package包/类
public Smoke() {
running = false;
ctx = getGraphicsContext2D();
width = getWidth();
height = getHeight();
particles = new CopyOnWriteArrayList<>();
lastTimerCall = System.nanoTime();
timer = new AnimationTimer() {
@Override public void handle(final long NOW) {
if (NOW > lastTimerCall + GENERATION_RATE) {
if (running && particles.size() < NO_OF_PARTICLES) particles.add(new ImageParticle());
if (particles.isEmpty()) timer.stop();
lastTimerCall = NOW;
}
draw();
}
};
registerListeners();
}
示例5: startMainLoop
import javafx.animation.AnimationTimer; //导入依赖的package包/类
private void startMainLoop() {
log.debug("Starting main loop");
mainLoop = new AnimationTimer() {
@Override
public void handle(long now) {
tpf = tpfCompute(now);
// if we are not in play state run as normal
if (!(getStateMachine().isInPlay() && getSettings().isSingleStep())) {
stepLoop();
}
}
};
mainLoop.start();
}
示例6: ChatPane
import javafx.animation.AnimationTimer; //导入依赖的package包/类
/**
* constructor
* @param username String
* @param messagePane AnchorPane
*/
public ChatPane(String username, AnchorPane messagePane) {
this.username = username;
this.setContent(messages);
this.setHbarPolicy(ScrollBarPolicy.NEVER);
this.setVbarPolicy(ScrollBarPolicy.ALWAYS);
messages.setId("chatPane");
messages.setFillWidth(false);
messages.minWidthProperty().bind(this.widthProperty());
messages.minHeightProperty().bind(this.heightProperty());
timer = new AnimationTimer(){
@Override
public void handle(long now){
Platform.runLater(()->{
scrollDown();
});
}
};
}
示例7: startTimer
import javafx.animation.AnimationTimer; //导入依赖的package包/类
private void startTimer()
{
timer = new AnimationTimer()
{
@Override
public void handle(long now)
{
WritableImage image = dash.snapshot(new SnapshotParameters(), null);
WritableImage imageCrop = new WritableImage(image.getPixelReader(), (int) getLayoutX(), (int) getLayoutY(), (int) getPrefWidth(), (int) getPrefHeight());
view.setImage(imageCrop);
}
};
timer.start();
}
示例8: Led
import javafx.animation.AnimationTimer; //导入依赖的package包/类
public Led() {
toggle = false;
lastTimerCall = System.nanoTime();
timer = new AnimationTimer() {
@Override public void handle(final long NOW) {
if (NOW > lastTimerCall + getInterval()) {
toggle ^= true;
setOn(toggle);
lastTimerCall = NOW;
}
}
};
init();
initGraphics();
registerListeners();
}
示例9: VuMeterSkin
import javafx.animation.AnimationTimer; //导入依赖的package包/类
public VuMeterSkin(final VuMeter CONTROL) {
super(CONTROL);
active = false;
lastTimerCall = 0l;
stepSize = new SimpleDoubleProperty((getSkinnable().getMaxValue() - getSkinnable().getMinValue()) / getSkinnable().getNoOfLeds());
timer = new AnimationTimer() {
@Override public void handle(final long NOW) {
if (NOW > lastTimerCall + PEAK_TIMEOUT) {
leds.get(peakLedIndex).getStyleClass().remove("led-peak");
peakLedIndex = Orientation.HORIZONTAL == getSkinnable().getOrientation() ? 0 : leds.size() - 1;
timer.stop();
}
}
};
init();
initGraphics();
registerListeners();
}
示例10: LedBargraphSkin
import javafx.animation.AnimationTimer; //导入依赖的package包/类
public LedBargraphSkin(final LedBargraph CONTROL) {
super(CONTROL);
ledList = new ArrayList<>(getSkinnable().getNoOfLeds());
stepSize = new SimpleDoubleProperty(1.0 / getSkinnable().getNoOfLeds());
lastTimerCall = 0l;
peakLedIndex = 0;
timer = new AnimationTimer() {
@Override public void handle(final long NOW) {
if (NOW > lastTimerCall + PEAK_TIMEOUT) {
ledList.get(peakLedIndex).setOn(false);
peakLedIndex = 0;
timer.stop();
}
}
};
init();
initGraphics();
registerListeners();
}
示例11: MediaRhythm
import javafx.animation.AnimationTimer; //导入依赖的package包/类
public MediaRhythm(String mediaString)
{
Media m = new Media(mediaString);
mediaPlayer = new MediaPlayer(m);
mediaPlayer.pause();
beatProperty = new SimpleLongProperty(0L);
isPlaying = false;
startedPauseAt = 0L;
timer = new AnimationTimer()
{
@Override
public void handle(long now)
{
update();
}
};
}
示例12: createContent
import javafx.animation.AnimationTimer; //导入依赖的package包/类
private Parent createContent() {
root = new Pane();
root.setPrefSize(800, 600);
frog = initFrog();
root.getChildren().add(frog);
timer = new AnimationTimer() {
@Override
public void handle(long now) {
onUpdate();
}
};
timer.start();
return root;
}
示例13: createContent
import javafx.animation.AnimationTimer; //导入依赖的package包/类
private Parent createContent() {
Pane root = new Pane();
root.setPrefSize(800, 600);
Canvas canvas = new Canvas(800, 600);
g = canvas.getGraphicsContext2D();
g.setFill(Color.BLUE);
root.getChildren().add(canvas);
populateDigits();
populateParticles();
AnimationTimer timer = new AnimationTimer() {
@Override
public void handle(long now) {
onUpdate();
}
};
timer.start();
return root;
}
示例14: start
import javafx.animation.AnimationTimer; //导入依赖的package包/类
@Override
public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(createContent());
scene.setOnMouseClicked(event -> {
bullet.setTarget(event.getSceneX(), event.getSceneY());
});
primaryStage.setTitle("Tutorial");
primaryStage.setScene(scene);
primaryStage.show();
AnimationTimer timer = new AnimationTimer() {
@Override
public void handle(long now) {
bullet.move();
}
};
timer.start();
}
示例15: createContent
import javafx.animation.AnimationTimer; //导入依赖的package包/类
private Parent createContent() {
Pane root = new Pane();
Canvas canvas = new Canvas(W, H);
g = canvas.getGraphicsContext2D();
root.getChildren().add(canvas);
for (int y = 0; y < grid[0].length; y++) {
for (int x = 0; x < grid.length; x++) {
grid[x][y] = new Tile(x, y);
}
}
AnimationTimer timer = new AnimationTimer() {
@Override
public void handle(long now) {
update();
}
};
timer.start();
algorithm = AlgorithmFactory.breadthFirst();
algorithmThread.scheduleAtFixedRate(this::algorithmUpdate, 0, 1, TimeUnit.MILLISECONDS);
return root;
}