如何将坐标和图像保存到整数变量上?

时间:2015-10-04 21:17:59

标签: java arrays

对于我的项目,我需要能够放置图像,然后将坐标x,y和图像名称“保存”到整数上。然后将整数放入数组中。因此,如果调用数组,它将给出图像名称和整数坐标。

    sticker [] placedsticker = new sticker [20];
    int slot = 0;
    int placedpic;
    else if (bluntSoundPlay){ //else if bluntSound is true
        EZ.addImage("blunt.png", clickX, clickY); //a blunt will be placed
        bluntsound.play(); //and blunt sound will play
        placedpic = 0;//each image has a different placed picnumber. ex. 0, 1, 2, 3.
        slot ++;//int slot increments every time image is placed so if it is at 1, it will fill in slot 0 of the array. If slot is 2 it will fill in slot 1 of the array.
                }

如何将所有这些信息保存到placementpic整数?而且,我如何将插槽1放入数组插槽0?

1 个答案:

答案 0 :(得分:0)

也许您的意思是说您希望将图像名称和坐标保存在数组中。而不是将它们保存在数组中的整数中。

你可以有一个(ImageName,X,Y)的SortedSet,然后简单地将该对象添加到数组中?这是你想要实现的目标吗?

您首先要创建一个Object来保存您的数据:

class ImageData {
    public String name;
    public int x;
    public int y;

    public ImageData(String name, int x, int y) {
        this.name = name;
        this.x = x;
        this.y = y;
    }
}

然后将它们添加到列表中:

Vector v = Vector();
ImageData image = ImageData("cat.jpg", 0, 0);
v.add(image);