【发布时间】:2014-05-20 21:14:25
【问题描述】:
我正在这里开发一个小游戏,我正在尝试使用左右箭头移动图像。
图像已被声明为 ImageView,正如您将在附加代码中看到的那样。
请随意纠正我!
package wordsfalling;
import java.*;
import java.net.URL;
import java.util.*;
import java.util.ResourceBundle;
import javafx.event.*;
import javafx.event.EventHandler;
import javafx.fxml.*;
import javafx.fxml.Initializable;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.*;
import javafx.scene.*;
/** * FXML Controller class *
* @author ad */
public class WordsFallingFXMLController implements Initializable {
@FXML
private ImageView bar;
// char [] alphapet = "ABCDEFGHIKLMNOPQRSTUVWXYS".toCharArray();
public void initialize(URL url, ResourceBundle rb) {
bar.setOnKeyPressed(new EventHandler<KeyEvent>()
{
@Override
public void handle(KeyEvent ke)
{
if (ke.getCode().equals(KeyCode.RIGHT))
{
bar.setX(4);
}
}
}
);
} }
我也努力修改和实施这个 JavaFX: Moving image with arrow keys and spacebar
但是没用!!
有什么建议吗?
提前致谢
【问题讨论】:
标签: javafx