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; }
@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(); }
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(); }
@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(); }
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(); }
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(); }
/** * 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(); }); } }; }
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(); }
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(); }
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(); }
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(); }
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(); } }; }
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; }
@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(); }
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; }
private Parent createContent() { Pane root = new Pane(); root.setPrefSize(800, 600); Canvas canvas = new Canvas(800, 600); g = canvas.getGraphicsContext2D(); AnimationTimer timer = new AnimationTimer() { @Override public void handle(long now) { t += 0.017; draw(); } }; timer.start(); root.getChildren().add(canvas); return root; }
@Override public void start(Stage primaryStage) throws Exception { Scene scene = new Scene(appRoot); scene.setOnKeyPressed(event -> keys.put(event.getCode(), true)); scene.setOnKeyReleased(event -> keys.put(event.getCode(), false)); primaryStage.setTitle("Tutorial 14 Platformer"); primaryStage.setScene(scene); primaryStage.show(); AnimationTimer timer = new AnimationTimer() { @Override public void handle(long now) { update(); } }; timer.start(); }
private Parent createContent() { root = new Pane(); root.setPrefSize(600, 600); player = new Player(); player.setVelocity(new Point2D(1, 0)); addGameObject(player, 300, 300); AnimationTimer timer = new AnimationTimer() { @Override public void handle(long now) { onUpdate(); } }; timer.start(); return root; }
public void createPerformanceTracker(Scene scene) { tracker = PerformanceTracker.getSceneTracker(scene); AnimationTimer frameRateMeter = new AnimationTimer() { @Override public void handle(long now) { float fps = getFPS(); fpsLabel.setText(String.format("Current frame rate: %.0f fps", fps)); } }; frameRateMeter.start(); }
private void createAnimation() { animation = new AnimationTimer() { @Override public void handle(long now) { long nextTimeStamp = timeStamp + timeStep; // Simulate in dt-sized steps until caught up. updateModel(now - timeStamp); while (nextTimeStamp < now) { step(); timeStamp = nextTimeStamp; nextTimeStamp = timeStamp + timeStep; } updateView(); } }; }
@FXML private void play() { if (activeGame != null) { Body body = world.getBodyList(); while (body != null) { world.destroyBody(body); body = body.getNext(); } root.getChildren().remove(0); /* Remove the previous gamePane. */ fpsLabel.setText(""); } activeGame = gamesBox.getValue(); Pane gamePane = new Pane(); activeGame.load(world, gamePane, objectsBox.getValue()); root.getChildren().add(0, gamePane); /* Add the gamePane at the bottom, underneath the controls. */ loopsBox.getItems().forEach(AnimationTimer::stop); loopsBox.getValue().setMaximumStep(maxStepCheck.isSelected() ? stepsBox.getValue() : Float.MAX_VALUE); loopsBox.getValue().start(); }
@Override public void captureScreen(OutputStream os) { final AnimationTimer timer = new AnimationTimer() { private int pulseCounter; @Override public void handle(long now) { pulseCounter += 1; if (pulseCounter > 2) { stop(); WebView view = (WebView) getView(); WritableImage snapshot = view.snapshot(new SnapshotParameters(), null); BufferedImage image = fromFXImage(snapshot, null); try (OutputStream stream = os) { ImageIO.write(image, "png", stream); } catch (IOException e) { throw new Ui4jException(e); } } } }; timer.start(); }
public Led() { getStylesheets().add(getClass().getResource("led.css").toExternalForm()); getStyleClass().add("led"); lastTimerCall = System.nanoTime(); timer = new AnimationTimer() { @Override public void handle(final long NOW) { if (NOW > lastTimerCall + getInterval()) { setOn(!isOn()); lastTimerCall = NOW; } } }; init(); initGraphics(); registerListeners(); }
/** * Returns an event stream that emits a timestamp of the current frame in * nanoseconds on every frame. The timestamp has the same meaning as the * argument of the {@link AnimationTimer#handle(long)} method. */ public static EventStream<Long> animationTicks() { return new EventStreamBase<Long>() { private final AnimationTimer timer = new AnimationTimer() { @Override public void handle(long now) { emit(now); } }; @Override protected Subscription observeInputs() { timer.start(); return timer::stop; } }; }
private void init(Stage primaryStage) { Group root = new Group(); primaryStage.setResizable(false); primaryStage.setScene(new Scene(root, 260,100)); //create a circle with effect final Circle circle = new Circle(20, Color.rgb(156,216,255)); circle.setEffect(new Lighting()); //create a text inside a circle final Text text = new Text (i.toString()); text.setStroke(Color.BLACK); //create a layout for circle with text inside final StackPane stack = new StackPane(); stack.getChildren().addAll(circle, text); stack.setLayoutX(30); stack.setLayoutY(30); //create a timeline for moving the circle timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); timeline.setAutoReverse(true); //one can add a specific action when each frame is started. There are one or more frames during // executing one KeyFrame depending on set Interpolator. timer = new AnimationTimer() { @Override public void handle(long l) { text.setText(i.toString()); i++; } }; //create a keyValue with factory: scaling the circle 2times KeyValue keyValueX = new KeyValue(stack.scaleXProperty(), 2); KeyValue keyValueY = new KeyValue(stack.scaleYProperty(), 2); //create a keyFrame, the keyValue is reached at time 2s Duration duration = Duration.seconds(2); //one can add a specific action when the keyframe is reached EventHandler<ActionEvent> onFinished = new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { stack.setTranslateX(java.lang.Math.random()*200); //reset counter i = 0; } }; KeyFrame keyFrame = new KeyFrame(duration, onFinished , keyValueX, keyValueY); //add the keyframe to the timeline timeline.getKeyFrames().add(keyFrame); root.getChildren().add(stack); }
public TimelineEventsSample() { super(70,70); //create a circle with effect final Circle circle = new Circle(20, Color.rgb(156,216,255)); circle.setEffect(new Lighting()); //create a text inside a circle final Text text = new Text (i.toString()); text.setStroke(Color.BLACK); //create a layout for circle with text inside final StackPane stack = new StackPane(); stack.getChildren().addAll(circle, text); stack.setLayoutX(30); stack.setLayoutY(30); //create a timeline for moving the circle timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); timeline.setAutoReverse(true); //one can add a specific action when each frame is started. There are one or more frames during // executing one KeyFrame depending on set Interpolator. timer = new AnimationTimer() { @Override public void handle(long l) { text.setText(i.toString()); i++; } }; //create a keyValue with factory: scaling the circle 2times KeyValue keyValueX = new KeyValue(stack.scaleXProperty(), 2); KeyValue keyValueY = new KeyValue(stack.scaleYProperty(), 2); //create a keyFrame, the keyValue is reached at time 2s Duration duration = Duration.seconds(2); //one can add a specific action when the keyframe is reached EventHandler<ActionEvent> onFinished = new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { stack.setTranslateX(java.lang.Math.random()*200-100); //reset counter i = 0; } }; KeyFrame keyFrame = new KeyFrame(duration, onFinished , keyValueX, keyValueY); //add the keyframe to the timeline timeline.getKeyFrames().add(keyFrame); getChildren().add(stack); }
public FXCanvasComposite(Composite container, int style) { super(container, style); this.setLayout(new GridLayout(1, false)); fxCanvas = new OldFXCanvas(this, SWT.NONE); fxCanvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); VBox root = getRoot(); AnimationTimer frameRateMeter = createAnimationTimer(label); label.textProperty().addListener(e -> { Recorder.log(FXCanvasComposite.this.getShell().getSize().x, FXCanvasComposite.this.getShell().getSize().y, label.textProperty().getValue()); }); frameRateMeter.start(); Scene scene = new Scene(root); fxCanvas.setScene(scene); ListViewTextUpdateThread listViewTextUpdateThread = new ListViewTextUpdateThread(textArea); listViewTextUpdateThread.start(); nameCol.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue())); TableViewUpdateThread tableViewUpdateThread = new TableViewUpdateThread(tableView); tableViewUpdateThread.start(); fxCanvas.addDisposeListener(e -> { tableViewUpdateThread.setStop(true); listViewTextUpdateThread.setStop(true); Recorder.setStop(true); }); }
@Override public void init() { List<YChartItem> item1 = new ArrayList<>(ELEMENTS); List<YChartItem> item2 = new ArrayList<>(ELEMENTS); List<YChartItem> item3 = new ArrayList<>(ELEMENTS); for (int i = 0 ; i < ELEMENTS ; i++) { YChartItem dataPoint; dataPoint = new YChartItem(RND.nextDouble() * 100, "P" + i); item1.add(dataPoint); dataPoint = new YChartItem(RND.nextDouble() * 100, "P" + i); item2.add(dataPoint); dataPoint = new YChartItem(RND.nextDouble() * 100, "P" + i); item3.add(dataPoint); } series1 = new YSeries(item3, CHART_TYPE, new RadialGradient(0, 0, 0, 0, 1, true, CycleMethod.NO_CYCLE, new Stop(0.0, Color.rgb(0, 255, 255, 0.25)), new Stop(0.5, Color.rgb(255, 255, 0, 0.5)), new Stop(1.0, Color.rgb(255, 0, 255, 0.75))), Color.TRANSPARENT); series2 = new YSeries(item1, CHART_TYPE, new RadialGradient(0, 0, 0, 0, 1, true, CycleMethod.NO_CYCLE, new Stop(0.0, Color.rgb(255, 0, 0, 0.25)), new Stop(0.5, Color.rgb(255, 255, 0, 0.5)), new Stop(1.0, Color.rgb(0, 200, 0, 0.75))), Color.TRANSPARENT); series3 = new YSeries(item2, CHART_TYPE, new RadialGradient(0, 0, 0, 0, 1, true, CycleMethod.NO_CYCLE, new Stop(0.0, Color.rgb(0, 255, 255, 0.25)), new Stop(0.5, Color.rgb(0, 255, 255, 0.5)), new Stop(1.0, Color.rgb(0, 0, 255, 0.75))), Color.TRANSPARENT); chart = new YChart(new YPane(series1, series2, series3)); chart.setPrefSize(600, 600); timeline = new Timeline(); lastTimerCall = System.nanoTime(); timer = new AnimationTimer() { @Override public void handle(final long now) { if (now > lastTimerCall + INTERVAL) { animateData(); long delta = System.nanoTime() - now; timeline.play(); lastTimerCall = now + delta; } } }; registerListener(); }
public static void start(GraphicsContext gc) { GameState.gameStatus=GlobalConstants.GameStatus.Running; new AnimationTimer() { public void handle(long currentNanoTime) { oldGameTime = currentGameTime; currentGameTime = (currentNanoTime - startNanoTime) / 1000000000.0; deltaTime = currentGameTime - oldGameTime; gc.clearRect(0, 0, GlobalConstants.CANVAS_WIDTH, GlobalConstants.CANVAS_WIDTH); //TODO This will have to be something like, currentScene.getEntities() updateGame(); renderGame(); } }.start(); }
public CanvasBubbles() { canvas = new Canvas(WIDTH, HEIGHT); ctx = canvas.getGraphicsContext2D(); image = new Image(getClass().getResourceAsStream("bubble.png")); particles = new ImageParticle[NO_OF_PARTICLES]; timer = new AnimationTimer() { @Override public void handle(final long NOW) { draw(); } }; for (int i = 0 ; i < NO_OF_PARTICLES ; i++) { particles[i] = new ImageParticle(image); } }
public ConnectedParticles() { canvas = new Canvas(WIDTH, HEIGHT); ctx = canvas.getGraphicsContext2D(); particles = new Particle[PARTICLE_COUNT]; timer = new AnimationTimer() { @Override public void handle(final long NOW) { draw(); } }; for (int i = 0 ; i < PARTICLE_COUNT; i++) { particles[i] = new Particle(); } }
public MouseGravityParticles() { CANVAS = new Canvas(WIDTH, HEIGHT); CTX = CANVAS.getGraphicsContext2D(); mousePos = new double[2]; timer = new AnimationTimer() { @Override public void handle(final long NOW) { draw(); } }; // Initialize particles particles = new double[ARRAY_LENGTH]; double initialSpeed = 1; int nextParticleIndex = 0; // next position to insert new particle for (int i = 0 ; i < NO_OF_PARTICLES; i++) { nextParticleIndex = (nextParticleIndex + NO_OF_FIELDS) % ARRAY_LENGTH; particles[nextParticleIndex + X] = RND.nextDouble() * WIDTH; particles[nextParticleIndex + Y] = RND.nextDouble() * HEIGHT; particles[nextParticleIndex + VX] = RND.nextDouble() * initialSpeed - initialSpeed * 0.5; particles[nextParticleIndex + VY] = RND.nextDouble() * initialSpeed - initialSpeed * 0.5; particles[nextParticleIndex + AX] = 0; particles[nextParticleIndex + AY] = 0; particles[nextParticleIndex + SPEED] = 0; } CANVAS.addEventFilter(MouseEvent.MOUSE_MOVED, EVENT -> { mousePos[0] = EVENT.getX(); mousePos[1] = EVENT.getY(); }); }
@Override public void init() { particles = new Particle[NO_OF_PARTICLES]; timer = new AnimationTimer() { @Override public void handle(final long NOW) { draw(); } }; for (int i = 0 ; i < NO_OF_PARTICLES ; i++) { particles[i] = new Particle(); } }
public Fire() { running = false; ctx = getGraphicsContext2D(); width = getWidth(); height = getHeight(); timer = new AnimationTimer() { @Override public void handle(final long NOW) { drawFast(); } }; particlesVisible = true; initialized = false; registerListeners(); }
/** * When the component is created, it initialize the component representation adding listener and MouseEvent * @param location type URL * @param resources type ResourceBundle */ @Override public void initialize(URL location, ResourceBundle resources) { super.initialize(location, resources); yScale.setTitle("Y Scale"); yScale.setMinValue(0.1); yScale.setMaxValue(50); chart.getData().add(samples); scaleAxis.setUpperBound(1.0); scaleAxis.setLowerBound(-1.0); yScale.valueProperty().addListener((observable, oldValue, newValue) -> { scaleAxis.setUpperBound(50*(double)newValue); scaleAxis.setLowerBound(-50*(double)newValue); }); new AnimationTimer() { @Override public void handle(long now) { //Each 7 frames of JavaFX we update if (runningTime % 7 == 0) { drawWave(); } runningTime++; } }.start(); }