当前位置: 首页>>代码示例>>Java>>正文


Java AnimationTimer类代码示例

本文整理汇总了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();

}
 
开发者ID:toivjon,项目名称:javafx-pong,代码行数:30,代码来源:PongApplication.java

示例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();
}
 
开发者ID:LtubSalad,项目名称:voogasalad-ltub,代码行数:26,代码来源:FXGameLoop.java

示例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();
}
 
开发者ID:hogeschool,项目名称:INFDEV-Homework,代码行数:18,代码来源:Main.java

示例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();
}
 
开发者ID:HanSolo,项目名称:particlesfx,代码行数:21,代码来源:Smoke.java

示例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();
}
 
开发者ID:AlmasB,项目名称:FXGL,代码行数:17,代码来源:GameApplication.java

示例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();
			});
		}
	};
}
 
开发者ID:GigaGagaGigoSoftware,项目名称:SagMa,代码行数:24,代码来源:ChatPane.java

示例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();
}
 
开发者ID:mars-sim,项目名称:mars-sim,代码行数:17,代码来源:FrostedPanel.java

示例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();
}
 
开发者ID:Simego,项目名称:FXImgurUploader,代码行数:17,代码来源:Led.java

示例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();
}
 
开发者ID:Simego,项目名称:FXImgurUploader,代码行数:19,代码来源:VuMeterSkin.java

示例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();
}
 
开发者ID:Simego,项目名称:FXImgurUploader,代码行数:21,代码来源:LedBargraphSkin.java

示例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();
		}
	};
	
}
 
开发者ID:GeePawHill,项目名称:contentment,代码行数:20,代码来源:MediaRhythm.java

示例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;
}
 
开发者ID:AlmasB,项目名称:FXTutorials,代码行数:19,代码来源:FroggerApp.java

示例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;
    }
 
开发者ID:AlmasB,项目名称:FXTutorials,代码行数:25,代码来源:ParticlesClockApp.java

示例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();
}
 
开发者ID:AlmasB,项目名称:FXTutorials,代码行数:19,代码来源:Main.java

示例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;
}
 
开发者ID:AlmasB,项目名称:FXTutorials,代码行数:27,代码来源:AlgorithmApp.java


注:本文中的javafx.animation.AnimationTimer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。