실제로 장기적으로 느려질 수 있습니다. 바이트 배열을 사용하여 바이트 [width] [height]와 같은 타일을 나타내는 것이 좋습니다. 단일 바이트가 충분한 정보를 더 이상 제공하지 않으면 spriteData [width] [height]와 같이 더 빠르고 관리하기 쉽고 쉽게 확장 할 수 있습니다. 당신은 게임 데이터를 저장하기 위해 이미지를 사용하여 주장하는 경우
그러나, 다음과 같은 것을 사용할 수 있습니다
File file = new File("mygamedata.jpg");
BufferedImage image = ImageIO.read(file);
// Getting pixel color at position x, y (width, height)
int colour = image.getRGB(x ,y);
int red = (colour & 0x00ff0000) >> 16;
int green = (colour & 0x0000ff00) >> 8;
int blue = colour & 0x000000ff;
System.out.println("Red colour component = " + red);
System.out.println("Green colour component = " + green);
System.out.println("Blue colour component = " + blue);
각 구성 요소 (0 ... 255)의 범위에있을 것입니다 그리고 당신은 할 수 당신이 모두 구성 요소를 추출 건너 뛰고 단순히
if (colour == 0x00ff0000) {
gc.drawImage(tile[whichTileYouWantForRed], x, y, null); // where x and y is the pixel you read.
}
즉, 색상을 사용할 수 있습니다, 또한 올바른 타일, 즉
Graphics2D gfx = (Graphics2D) offScreenImage.getImage();
if (red == 120 && green == 0 && blue == 0) {
gc.drawImage(tile[whichTileYouWantForRed], x, y, null); // where x and y is the pixel you read.
}
을 결정하는 것을 사용
(어쨌든 조금 더 빨라서 실제로 원하는 것입니다.)
괜찮아요. 내 게임이 이미지 (예 : "mygamedata.jpg")에 따라 각 타일을 꺼내려고합니다. – bigbass1997
위의 코드를 약간 추가했습니다 ... 도움이됩니까? –
에는 x 및 y 위치를 자동으로 높이는 방법이 있습니다. 그래서 그것은 각 위치를 통과합니까? – bigbass1997