考慮到每一個塊需要比前一個進一步
List<Block> blocks = new LinkedList<Block>();
Random rnd = new Random(System.currentTimeMillis());
int x = 400;
while (youNeedMoreBlocks)
{
int offset = rnd.nextInt(400) + 100; //500 is the maximum offset, this is a constant
x += offset; //ofset will be between 100 and 400
blocks.add(new Block(R.drawable.block, x, platformheight));
//if you have enough blocks, set youNeedMoreBlocks to false
}
但是這看起來過於簡單化了我。要麼我不明白你的問題,要麼就是那麼簡單。
編輯:
對於這樣的任務:
block.setY(three_quarters - 10);
block2.setY(three_quarters - 10);
block3.setY(three_quarters - 10);
您需要修改與循環:
List<Block> blocks = new LinkedList<Block>();
Random rnd = new Random(System.currentTimeMillis());
int x = 400;
while (youNeedMoreBlocks)
{
int offset = rnd.nextInt(400) + 100; //500 is the maximum offset, this is a constant
x += offset; //ofset will be between 100 and 400
Block tmp = new Block(R.drawable.block, x, platformheight);
tmp.setY(three_quarters - 10);
//do with tmp everything you need to apply to each block
blocks.add(tmp);
//if you have enough blocks, set youNeedMoreBlocks to false
}
另一種明智的想法是,當產生對需求的塊球員接近地圖的邊緣,所以你有更快的加載時間。
一個'for'循環和一些'Math.random()'調用。你有沒有嘗試google搜索它... – 2012-04-09 21:47:03