【发布时间】:2014-03-27 17:17:33
【问题描述】:
我正在尝试制作像 Space Invaders 这样的小游戏。我正在将 JavaFX 与 Netbeans 6.9 一起使用,但在其他地方找不到答案,所以我想我会在这里问。
我有一张宇宙飞船的图像,我想用箭头键移动它。当我按空格键时,它应该发射导弹。导弹可以摧毁陨石。
这是我当前的代码:
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.animation.Timeline;
import javafx.animation.Interpolator;
var x: Number;
Timeline {
repeatCount: Timeline.INDEFINITE
autoReverse: true
keyFrames: [
at (0s) {x => 500.0},
at (10s) {x => -100.0 tween Interpolator.LINEAR}
]
}.play();
Stage {
title: "Shoot"
scene: Scene {
fill: Color.BLACK
width: 800
height: 500
content: [
ImageView {
x: 500 y: 25
image: Image {
url: "{__DIR__}earth.jpg";
}
}
ImageView {
translateX: bind x
x: 150 y: 300
image: Image {
url: "{__DIR__}meteorite.png";
}
}
ImageView {
x: 400 y: 450
image: Image {
url: "{__DIR__}spaceship.png";
}
}
]
}
}
提前致谢。
【问题讨论】: