2015-10-04 62 views
-1

對於我的項目,我需要能夠放置圖像,然後將座標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. 
       } 

我該如何將所有這些信息保存到定位圖整數?另外,我如何將插槽1放入陣列插槽0?

+0

難道這就是用來保存所有到一個變量/整數? – user5329697

+4

這甚至意味着什麼?將所有內容保存爲整數! – QuakeCore

+2

如果您或其他人可以弄清楚如何將圖像存儲爲32位整數,然後將其恢復,我會付出高昂的代價;)請澄清您的作業要求。 – hotzst

回答

0

也許你打算說你想保存一個圖像名稱和座標在一個數組中。與將它們保存在數組中的整數不同。

你可以有一個SortedSet的(ImageName,X,Y),然後簡單的添加該對象數組?這是你想要達到的目標嗎?

你要首先創建一個對象來保存數據:

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); 
+0

我有這樣的東西'sticker [] placedsticker = new sticker [20]; '保存我的數據。它創建了20個可以存儲我的信息的空間。 – user5329697

+0

@ user5329697而你的'sticker'有你的圖像名稱,x座標和y座標的字段? –

+0

這是我的貼紙班。 '公共類貼紙{ \t EZImage image; \t INT X = -100; //將這個圖象戲外 \t INT Y = -100; \t EZSound聲音; \t String imageName; \t \t貼紙(字符串文件名,字符串newSound,INT下一頁末,INT newY){ \t \t \t圖像= EZ.addImage(文件名,X,Y); \t \t \t imageName = fileName; \t \t \t setPosition(newX,newY); \t \t \t sound = EZ.addSound(newSound); \t \t} \t \t空隙setPosition兩種(INT下一頁末,INT newY){ \t \t \t X =下一頁末; \t \t \t y = newY; \t \t \t圖片。translateTo(newX,newY); \t \t} \t \t INT getXPosition(){ \t \t \t返回X; \t \t} \t \t INT getYPosition(){ \t \t \t返回ÿ; \t \t} } ' – user5329697

相關問題