0

作成したクラスを含むリンク リストを取得しましたが、リストに新しいインスタンスを追加するたびに、リスト内の他のすべての要素が同じデータを取得します。

これが私のリストにあるクラスです。

public class ZitEntity 
{
private int mSize;
public boolean poped;
private boolean done;
private Canvas can;
private int count;
private  static Vector2D mPosition;
private int ms;
private Bitmap Zit;

public ZitEntity(int a, int b)
{
    mSize = 20;
    poped = false;
    done = true;
    ms = 3;
    mPosition = new Vector2D(a,b);
    Zit = Bitmap.createBitmap(mSize*2, mSize*2, Bitmap.Config.ARGB_8888);
}

2 番目のクラスでは、リストを作成します。

private LinkedList<ZitEntity> entityList;

そしてコンストラクターでリストを開始します。

entityList = new LinkedList<ZitEntity>();

ここで、新しいインスタンスをリストに追加します。

private void createEntity()
{
    Random generator = new Random();
    int a = generator.nextInt(10);
    if(a==5)
    {   
        int x = generator.nextInt(ZitGame.height-60)+20;
        int y = generator.nextInt(ZitGame.width-120)+20;
        entityList.add(new ZitEntity(x,y));
        Log.v("add entity", "new entity");
    }
}
4

1 に答える 1

3

mPosition を static として宣言しているため、各アイテムの最新の位置を取得するたびに

于 2012-04-22T18:17:05.070 に答える