我正在尝试在JavaFX中实现一个矩形形状的左右移动。下面是我的代码:
public void start(Stage primaryStage) throws Exception {
AnchorPane ancPane = new AnchorPane();
final Rectangle rect = new Rectangle();
rect.setHeight(50);
rect.setWidth(50);
ancPane.getChildren().add(rect);
Scene scene = new Scene(an
我有一个游戏,有一个船对象(与JavaFX多边形)。当我用钥匙(通过EventHandlers和AnimationTimers)移动飞船时,它会向上移动。当我放手的时候,它应该把加速度改变为-4,然后它会不断地把-4从飞船的速度中带走,直到它的速度达到0。然而,由于船可以向各个方向移动,所以当船向前移动时,速度有时是负的。因此,当我试图在速度为负值时停船时,它不会发生,而且船会继续向后移动。
我尝试了一些计算,当船的速度是负的和前进,但它变得有点过于复杂,我相信它没有工作。
以下是船舶计算速度x方法的程序:
AnimationTimer calculateVelocityX = new Ani
我在做游戏。我创建一个数组来保存我所有的形状。我需要每0.1秒移动一次形状,或者更小的东西。同时,我也有一个圆圈跟着我的鼠标。我需要能够一直跟随我的鼠标移动圆圈,但是我还没有找到一种方法来移动其他的圆圈,每秒钟一点点。当我试图移动其他圆圈时,它们都会在javaFX窗口加载之前立即移动。
这是我的阵列
我创建了一个圆并将它添加到我的形状数组中
ArrayList<Shape> Objects = new ArrayList<Shape>();
Circle I = ClassObjects.getCircle(randomWidth,randomX,randomY);
我在看一本libgdx的书。在其中,作者使用动画类来播放动画。以下是有关守则:
public class Flappee{
private float animationTimer = 0;
private static final float FRAME_DURATION=0.25f;
public Flappee(Texture texture){
TextureRegion[][] flappeeTextures = new TextureRegion(texture).split(118,118);
collisionCircle = new Circle(x,
这是我为创建pacman而编写的一个程序。现在我想让帕克曼从一个随机的起点直线移动到一个随机的目标点。你能建议一下怎么做吗。
import javax.swing.JFrame;
/**
* Main class for pacman example. All it does is create a frame and put
* the pacman panel in it.
*/
public class PacmanGUI extends JFrame{
private Pacman pc;
public PacmanGUI(){
我有背景(Rectangle)和Group添加到画布的root中。我将较小的Rectangle (播放器)添加到组中,然后通过AnimationTimer (自定义没有线程睡眠)移动矩形。当小Rectangle到达中间X位置时,我想从场景中移除这个矩形。删除后,矩形将保留在画布中,直到我移动/调整大小窗口。如何刷新画布,使删除的矩形消失?
public class Test extends Application {
public static final int TILE_SIZE = 50;
public static final int WIDTH = 15;
我正在尝试更改AnimationTimer的速度,以便代码运行得更慢,以下是我到目前为止拥有的代码:
AnimationTimer timer = new AnimationTimer() {
@Override
public void handle(long now) {
if (upOrDown != 1) {
for (int i = 0; i < 4; i++) {
snakePositionDown[i] = snake[i].getX();
sna
所以我现在有一个用JavaFX在屏幕上移动弹跳球的程序,现在我已经尝试在我的时间轴动画中的Duration.millis()下重新格式化某些值,我把它放得越低球走得越快,但是,有人告诉我这不是最好的方法,相反,我应该问一下动态速度来添加到我的程序中,这是我的球移动的代码:
public class BallPane extends Pane {
public final double radius = 5;
public double x = radius, y = radius;
public double dx = 1, dy = 1;
public Circle circle
我有个小问题。在动画期间执行paintComponent()方法时,我必须不断更新变量bgImage。但这需要很长的时间,这样动画就会慢下来。
问题的代码块:
public class ProblemClass extends JComponent {
private static final int FRAME_FREQUENCY = 30;
private final Timer animationTimer;
public ProblemClass() {
this.animationTimer = new Timer(1000 / FRAME_
我正在尝试将我的系统时间添加到我的应用程序中,为此,我设置了一个标签,我想用我的值不断地改变它。
我使用的是JavaFx和scenebuilder。
我从这个小代码开始,但我不知道如何将变量dateString放入标签日期中。
SimpleDateFormat d = new SimpleDateFormat ("dd/MM/yyyy" );
SimpleDateFormat h = new SimpleDateFormat ("hh:mm");
Date currentTime_1 = new Date();
String dateString =
我正在尝试做一个游戏,使用类AnimationTimer来处理它。我的代码摘要如下所示:
主类
object Game extends JFXApp{
def showMenu{
//code that show the .fxml layout and controller will handle the controller
}
def showInstruction{
//code that show the .fxml instruction
}
def showGame():Unit = {
我创建了一个简单的脚本来移动键盘输入的球员,虽然现在我想移动球员的触摸输入,我该怎么做?
下面是我的代码,那么我该如何编辑这段代码使其正常工作呢?我有跳跃工作,但不知道怎么做才能搬家?
using UnityEngine;
using System.Collections;
public class MoveGround : MonoBehaviour
{
public float y = 0f;
public Rigidbody2D rb;
//public float x = 0f;
//public float z = 0f;
// Use t
我想使用AnimationTimer在屏幕上移动一个矩形。我想这样做,因为我想学习AnimationTimer是如何工作的,这样我就可以用它做一个游戏。我目前在这样做时遇到了一些问题。 public class FXTimer extends Application {
@Override
public void start(Stage primaryStage) {
Rectangle rect = new Rectangle(1000,100,100,100);
AnimationTimer timer = new Animatio
我正在试着打印Hello World!在AnimationTimer中,看看它是否能正常工作。没有错误或警告,但它不工作。
import javafx.animation.AnimationTimer;
public class Example {
public static void main(String[] args) throws Exception {
AnimationTimer timer = new AnimationTimer(){
@Override
public void handle(long