SpriteSheet缓冲图像数组

时间:2012-10-06 17:29:52

标签: java image bufferedimage sprite-sheet

public BufferedImage[] sprites1()
{
    BufferedImage[] sprites = new BufferedImage[6];
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            sprites[(i * 2) + j] = bigImg.getSubimage(j * 64, i * 64, 64, 64);
        }
    }
    return sprites;
}

public BufferedImage[] sprites1Fliped()
{
    BufferedImage[] sprites = new BufferedImage[6];
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            BufferedImage dimg = new BufferedImage(64, 64, sprites1()[i].getType());  
            Graphics2D g = dimg.createGraphics();  
            g.drawImage(sprites1()[i], 0, 0, 64, 64, 64, 0, 0, 64, null);  
            g.dispose();
            sprites[i] = dimg;
        }
    }
    return sprites;
}


ImageIcon img1a = new ImageIcon(images.sprites1()[5]);
ImageIcon img2a = new ImageIcon(images.sprites1()[2]);
ImageIcon img3a = new ImageIcon(images.sprites1()[3]);
ImageIcon img4a = new ImageIcon(images.sprites1()[0]);
ImageIcon img5a = new ImageIcon(images.sprites1()[1]);
ImageIcon img6a = new ImageIcon(images.sprites1()[4]);


    setLayout(new GridBagLayout());
    layout.add(l1); //l1 is a label with img1a, l2 img2a, ect.
    layout.add(l2);
    layout.add(l3);
    layout.add(l4);
    layout.add(l5);
    layout.add(l6);
    add(layout);
    GridBagConstraints c = new GridBagConstraints();
    c.weighty = 1.0;
    c.weightx = 0;
    c.anchor = GridBagConstraints.PAGE_END;
    add(b1, c);

Frame

问题是面板应该从精灵表中显示橙色,黄色,然后是蓝色的龙。相反,它显示了翻转的橙色龙,橙色的龙和翻转的蓝色龙。

SpriteSheet (这是128x192)(每个是64x64)

1 个答案:

答案 0 :(得分:0)

我通过将图像放在正确的文件夹中来修复我自己的问题,替换旧的精灵图像表。