java - 动画运行时使新动画不可能(在动画期间禁用 setOnMouseClicked)
问题描述
我一直在寻找一种方法来做到这一点,但我似乎无法找到 javafx 的解决方案(我只能在 jQuery 和 javascript 中找到它)。我有一个游戏,你可以在 Mouseclick 上旋转图块(ImageViews),我用
setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
update();
}
};
更新有这个:
public void update() {
Animation animation = new RotateTransition(Duration.millis(100), this);
animation.setByAngle(90);
animation.play();
tile.rotate();
}
问题是,当我在瓷砖上单击得太快(当它仍在旋转时)时,它会被搞砸并卡在例如 60 度。我只是想让它在动画运行时无法单击 imageView。请帮我。提前致谢!
解决方案
您可以添加一个布尔值来存储该功能当前是否正在运行并相应地禁用/启用它。
boolean currentlyPlaying = false;
node.setOnMouseClicked(event -> {
if (!currentlyPlaying)
update();
});
public void update() {
Animation animation = new RotateTransition(Duration.millis(100), this);
animation.setByAngle(90);
animation.play();
currentlyPlaying = true;
animation.setOnFinished(event -> currentlyPlaying = false;);
tile.rotate();
}
推荐阅读
- swift - 如何在 Swift / MacOS 中将菜单项添加到顶部导航栏
- powershell - 目标计算机和部署组上的 Powershell
- webpack - 在 Webpack 4 中 Uglify 之后运行 optimize-js
- c# - 为 winforms 应用程序存储 AuthClientSecret 的安全位置?
- html - 父母的反增量,但孩子的内容
- amp-html - AMP 验证错误:“标签 'head > style[amp-boilerplate]' 中的强制文本缺失或不正确。”
- grep - 对于大于 200MB 的较大文件,grep 无法正常工作
- python - 在字典中使用列表作为 VALUE
- ios - 如何让 Google Speech API 的异步语音转录适用于 iOS?
- javascript - serializeObject 试图将字符串数字转换为整数(更新)