简体   繁体   中英

How do I save the coordinates and image onto a integer variable?

For my project, I need to be able to place an image, then have the coordinates x, y and the image name be "saved" onto a integer. The integer is then placed into an array. So if the array gets called up, it will give an image name and integer coordinates.

    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.
                }

How would I save all this information to the placedpic integer? And also, how would I put slot 1 into array slot 0?

Perhaps you meant to say you would like to save an image name and coordinates in an array. As opposed to saving them in an integer in an array.

You could have a SortedSet of (ImageName, X, Y) and then simple add that object to array? Is this what you're trying to achieve?

You would first create an Object to hold your data:

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;
    }
}

Then add them to a list:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM