- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我们用 Java 开发的游戏板中,我们希望在按下按钮时显示一种滚动的骰子。我们正在尝试使用以下图像作为 Sprite :
所以当按下按钮时,会发生以下情况:
private void startAnimationDie(final JPanel panel) {
int launchResult = /* getting a launch dice result from the core game (from 1 to 6)*/
new Thread() {
public void run() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
BufferedImage[] animationBuffer = initAnimationBuffer();
BufferedImage[][] exactDieFaces = initExactDieFaces();
int launchResult = coreGame.launchDie();
coreGame.getMyPartecipant().setLastLaunch(launchResult);
AnimationSprite animation = new AnimationSprite(animationBuffer, Constants.DIE_ANIMATION_SPEED);
animation.start();
JLabel resultDie = new JLabel();
resultDie.setBounds(60, 265, Constants.DIE_SIZE, Constants.DIE_SIZE);
for (int counter = 0; counter < Constants.DIE_ANIMATION_SPEED * 100; counter++) {
animation.update();
//panel.removeAll();
panel.updateUI();
//System.out.println("infor");
resultDie.setIcon(new ImageIcon(animationBuffer[counter % Constants.ROTATIONS]));
panel.add(resultDie);
panel.updateUI();
updateUI();
}
panel.removeAll();
panel.updateUI();
AnimationSprite resultAnimation = new AnimationSprite(exactDieFaces[launchResult - 1], 6);
resultAnimation.start();
resultAnimation.update();
System.out.println("0");
resultDie.setIcon(new ImageIcon(exactDieFaces[launchResult - 1][0]));
System.out.println("1");
resultDie.setBounds(60, 265, Constants.DIE_SIZE, Constants.DIE_SIZE);
System.out.println("2");
panel.add(resultDie);
try {
Thread.sleep(200);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
userPlayer.getGamePanel().makePossibleMoveFlash();
}
});
} catch (Exception ex) {
}
}
}.start();
其中,exactDieFaces 包含根据正在启动的 pawn 颜色的骰子面,该面将在模拟滚动完成后显示;另一方面,animationBuffer 包含从 Sprite 图像中获取的 40 或 50 个所有颜色的随机面,如下所示:
private BufferedImage[] initAnimationBuffer() {
BufferedImage[] result = new BufferedImage[Constants.ROTATIONS];
int rowSprite, colSprite;
Random random = new Random();
for (int i = 0; i < Constants.ROTATIONS; i++) {
rowSprite = 1 + random.nextInt(5);
colSprite = 1 + random.nextInt(5);
result[i] = DieSprite.getSpriteExact(0 /* offset */,colSprite, rowSprite);
}
return result;
}
问题是动画期间没有显示任何内容:我预计会看到许多骰子面一个接一个地变化,直到 for 循环结束,但没有显示任何内容......我唯一看到的是根据彩色典当已经启动了骰子,但同时什么也没有......你能帮助我吗?
最佳答案
如果我正确理解您的代码,您将尝试在同一个 for 循环中多次更新 UI。动画不是这样运作的。您需要一个计时器,它会定期通知您移至下一帧进行查看。
了解如何使用计时器的一个好起点是 here在 Java 教程中。
关于Java Swing Sprite : how to simulate a rolling dice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28321238/
我创建了一个简单的掷骰子程序。但是while循环不会在什么时候停止roll1 和 roll2 相等。总数并没有加起来。程序运行无限次,我必须停止它。请帮忙。 输出: Roll #1: 1 Roll #
来自 the exactly-once KIP ,关于使用 InitPidRequest 重启应用程序时的生产者幂等性: 2.1 When an TransactionalId is specifie
我正在尝试使用 native CameraRoll.getPhotos API 获取相机胶卷照片。我发现文档不是很好的问题。在 react-native official documentation提
我有两个数据框:一个有多级列,另一个只有单级列(这是第一个数据框的第一级,或者说第二个数据框是通过对第一个数据框进行分组计算的)。 这两个数据框如下所示: first dataframe-df1 se
您好,请帮我使用子字符串方法,我不知道如何仅将特定单词大写 private static void viewAllItems(ArrayList itemList) { // TODO
我正在制作一个硬币从左边滚进来的动画。 到目前为止,我可以通过 RotateAnimation 使其旋转并通过 TranslateAnimation 使其移动。 现在我无法尝试让这两个同时运行。 {
我的 mysql 查询的最后一行有问题。我只想要最后一列(总计),其余行我希望它们为 NULL。 查询: SELECT q.id_socio, q.nome, q.nif, q.num_mecanog
我试图让我的代码中的按钮滚动到中心视频的顶部,但我不太确定我该怎么做?我试图将按钮作为一个类,例如class="button"然后我试着让它居中,但它不起作用。我没有在 css 中做任何与按钮相关的事
Google I/O 为 % 的人发布了一个分阶段推出的选项,我试图将一个 api 上传到市场,但找不到这个分阶段推出的选项,有人可以帮助我如何实现这一目标。 问候 sleep 最佳答案 转到“上传新
我需要一个滚动哈希来搜索文件中的模式。 (我正在尝试使用 Rabin-Karp string search algorithm )。 我了解一个好的 Hash 如何工作以及一个好的 Rolling H
环境:TFS 2010 我在 TFS 2010 上遇到了一个奇怪的问题。 我创建了一个滚动构建,并将其设置为每 30 分钟触发一次。 通常,它工作正常。我发现构建一天被触发了好几次。 然后放长假,回来
在 TFS 2010 上,我们设置了一个构建脚本,以自动运行并部署到我们的测试环境中,频率不超过每 4 小时一次。因此,构建定义的触发器是“滚动构建 - 累积 checkin ,直到先前的构建完成”,
我有一个审计表,我们在其中记录对数据库中字段的更改。我有一个查询,我能够从审计中获取有关几列、它们记录的更改以及与适用 ID 关联的时间的数据子集。以下是输出示例: ID ada
我按周数对数据框进行分组,并得到一列看起来像这样的数字 0 0.0 1 0.0 2 0.0 3 0.0 4 0.0 5 0.0 6 0.0 7 0.0 8 0.0 9 0.0 10 0.0 11 0.
我有一个如下所示的数据集 (x): DATE WEEKDAY A B C D 2011-02-04 Fri
在后记中,roll运算符非常笼统,难以形象化。你如何确保你在正确的方向上滚动? 我想在 roll 上得到一个可靠的句柄因为我希望能够使用变量来转换函数 /f { % x y z /z exch
data.table很棒,因为我可以进行滚动连接,甚至可以在组内进行滚动连接! library(data.table) set.seed(42) metrics metrics[calendar,r
我有一个重复调用 roll 的 for 循环,我想反转创建数组的顺序。 我想我忽略了一些琐碎的方法来做到这一点,但到目前为止我只找到了 10000 3 5 种不这样做的方法。 In [1]: from
[编辑] 我在numbtongue之后重建了我的代码暗示。现在看起来完全不同了,而且运行得很好。只不过它只能工作一次!滚了一圈之后就不再滚了...我有两种功能:一种用于过渡,另一种用于替换内容。在“t
实际上,我正在编写一个小型太空射击游戏(2.5D,俯 View )。玩家可以沿着 XZ 轴移动并通过右侧的迷你摇杆(游戏 handle )旋转宇宙飞船或查看光标位置(键盘 + 鼠标)。 因此,运动和旋
我是一名优秀的程序员,十分优秀!