我的GUI上的原点(0,0)向上移动了大约25/26像素。因此,GUI的左上角似乎代表0,25或0,26。我用双缓冲区来画东西。基本上,每当我试图在缓冲区中以0,0绘制某个东西时,它就会出现在屏幕外。
例如,下面是我试图生成的棋盘格图案的屏幕截图,从0,0开始。虽然水平方向看起来不错,但请注意顶部的切碎棋盘。高度是480,可以被32整除。请记住,棋盘格图案应该能完美填充。
这是我的代码(被剪成不相关的部分):
public class Dekari_gameGUI extends JFrame implements KeyListener {
// Resources
private final String imagePath = "Resources/Images/";
private final String spriteSheetPath = imagePath + "Sprite Sheets/";
private final String soundPath = "Resources/Sounds/";
private final String dataPath = "Resources/Data/";
private BufferedImage[][] sprites;
private Timer playerMovementTimer = new Timer();
//Game variables
private int pX = 0, pY = 0;
private short pDir = -1, pLastDir = 0, pAniStage = 0, counter = 0;
//Graphics and paint variables
private Graphics buffer;
private Image offscreen;
private Dimension dim;
//Internal variables, used for loops and placeholders
private int a, b, c, d;
/*
____ _ _
/ ___|___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __
| | / _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__|
| |__| (_) | | | \__ \ |_| | | |_| | (__| || (_) | |
\____\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_|
*/
public Dekari_gameGUI() {
// Declaring GUI setup
setResizable(false);
setTitle("Dekari RPG Indev v1.0");
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setSize(640, 480);
setBackground(Color.GREEN);
setLocationRelativeTo(null); //Centers the window
splitSpriteSheets(); //Sets up resources
dim = getSize();
offscreen = createImage(dim.width, dim.height);
buffer = offscreen.getGraphics();
*snip*
setVisible(true);
}
*snip*
/*
____ _ _
| _ \ __ _(_)_ __ | |_
| |_) / _` | | '_ \| __|
| __/ (_| | | | | | |_
|_| \__,_|_|_| |_|\__|
*/
public void paint(Graphics g) {
//Clears the buffer
buffer.clearRect(0, 0, dim.width, dim.width);
//Drawing images to the buffer
buffer.setColor(Color.BLACK);
boolean paint = true;
//This is my checkerboard drawing function
for (a = 0; a < getWidth() / 32; a++) {
for (b = 0; b < getHeight() / 32; b++) {
if (paint) {
paint = false;
buffer.fillRect(a * 32, b * 32, 32, 32);
} else {
paint = true;
}
}
}
if (pDir == -1) //If the player is not moving
//Draws player in an idle stance facing last moved direction
buffer.drawImage(sprites[0][4 * pLastDir], pX - 24, pY - 32, this);
else //If the player is moving
//Draws player in a movement state facing the current direction
buffer.drawImage(sprites[0][pAniStage + (4 * pLastDir)], pX - 24, pY - 32, this);
//Drawing the buffer to the frame
g.drawImage(offscreen, 0, 0, this);
}
public void update(Graphics g) {
paint(g);
}
}
不,不是。你直接画在框架上,框架的边界装饰画在框架的边界内。欢迎来到为什么你不应该直接画在顶级容器上的奇妙世界。
相反,将自定义绘制移动到另一个组件,例如JPanel
,并将其直接添加到框架中。这将被布置成这样的距离,以便定位在框架内
通过重写面板的getPreferredsize
方法并返回适当的值,您可以使用JFrame#pack
来打包框架,使其满足内容的首选大小要求。这将确保内容处于首选大小,并且窗口装饰围绕着它。
还要记住,Swing组件在默认情况下是双缓冲的,所以你不必重新设计轮子,除非你有特殊的需要。。。
要了解更多信息,请看我如何设置中间?即使重新调整尺寸,如何获得屏幕的精确中间位置?为什么顶层容器中的覆盖涂料如此糟糕?为什么不直接在JFrame内部绘制更多细节呢
我有一个ReactorKafka项目,它消耗来自Kafka主题的消息,转换消息,然后写入到另一个主题。 我的理解是,只有在Reactor中成功完成所有顺序步骤后,才会提交偏移量。对吗?我想确保不会处理下一条记录,除非当前记录成功发送到目标Kafka主题。
我有如下代码 每当我通过将其设置为实体来保存到我的数据库时,它会添加5:30作为偏移量
问题内容: MySQL中有没有一种方法可以计算任何时区的偏移量?例如,要获取时区中的本地时间。我想做的是计算该时区的偏移量,并将该偏移量添加到GMT以获得本地时间。 问题答案: 如果要计算某个时区(例如,美国/温哥华)与UTC的时差,则可以按照以下步骤进行操作: 为此,您首先需要按照以下概述将时区信息加载到mysql中:http : //dev.mysql.com/doc/refman/5.0/e
问题内容: 我对使用Kafka和Zookeeper时在哪里存储偏移量感到困惑。在某些情况下,偏移似乎存储在Zookeeper中,而在其他情况下,偏移存储在Kafka中。 是什么决定偏移量存储在Kafka还是Zookeeper中?优点和缺点是什么? 注意:当然,我也可以将偏移量单独存储在其他数据存储区中,但这并不是本文的内容。 有关我的设置的更多详细信息: 我运行以下版本:KAFKA_VERSION
问题内容: 在SQL Server中,我需要找到给定的偏移量。 我已经研究了文档,并且有各种方法可以更改偏移量,但是没有一种方法可以了解特定值的偏移量(很抱歉,如果我错过了它)。 好吧,我想出了以下代码,尽管看起来似乎可行,但我觉得它太复杂了。 我仍然必须转换为+00:00格式,但想检查是否有更好的方法。 谢谢! 问题答案: datepart函数具有tz选项,它是时区偏移量(以分钟为单位)。
可以从输入主题的特定偏移量到结束偏移量进行Kafka流处理吗? 我有一个Kafka流应用程序消耗输入主题,但由于某种原因失败了。我修复了问题并再次启动它,但它从输入主题的最新偏移量开始消耗。我知道应用程序已处理的输入主题的偏移量。现在,我如何将输入主题从一个偏移量处理到另一个偏移量。我正在使用合流平台5.1.2。