これは、実際には長期的には遅くなる可能性があります。タイルを表すのにバイト配列、つまりbyte [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