내 GUI의 원점 (0,0)이 약 25/26 픽셀만큼 위로 이동했습니다. 따라서 GUI의 맨 위 왼쪽 구석은 0,25 또는 0,26을 나타내는 것으로 보입니다. 사물을 그릴 때 이중 버퍼를 사용하고 있습니다. 기본적으로, 0,0에서 내 버퍼에 무언가를 그리려고 할 때마다, 화면 밖에서 보입니다.내 GUI의 원점 위치가 약 25/26 픽셀입니다.
예를 들어, 생성하려고 시도한 체커 보드 패턴의 스크린 샷은 0,0부터 시작합니다. 그것이 수평으로 잘 보이더라도, 정상에 잘게 잘린 바둑판을주의하십시오. 높이는 32로 나눌 수있는 480입니다. 바둑판 무늬가 완벽하게 채워야합니다.
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);
}
}
대단히 감사합니다. –
@RemiliaScarlet 도움이 되었으면합니다. – MadProgrammer
문제를 해결하는 데 도움이된다면 [답변] (http://meta.stackexchange.com/a/5235/155831)을 입력하십시오. –