gpt4 book ai didi

java - 我需要在游戏中显示分数,该分数可以随着玩家获得分数而更新

转载 作者:行者123 更新时间:2023-12-01 13:30:27 25 4
gpt4 key购买 nike

我已经尝试让它工作很长时间了,但我被困住了。我有一个“有效”的评分系统(当玩家收集硬币时,它的分数会增加)但我一生都无法让它在屏幕左上角显示分数(或者得到它完全显示)。我尝试过像这样使用 JLabel:

JLabel scoreLabel = new JLabel("Score: 0");
public void someoneScored()
{
Score++;
scoreLabel.setBounds(5, 5, WIDTH, HEIGHT);
scoreLabel.setText("Score: " + Score);
}

最佳答案

您需要将 label 放入 panel 中,如下例所示:

JLabel scoreLabel = new JLabel("Score: 0");
add(scoreLabel);/// assuming you have Jpanel class

public void someoneScored()
{
Score++;
scoreLabel.setBounds(5, 5, WIDTH, HEIGHT);
scoreLabel.setText("Score: " + Score);
}

关于java - 我需要在游戏中显示分数,该分数可以随着玩家获得分数而更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21599638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com