各ブロックが前のブロックよりも遠くにある必要があることを考えると、
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
}
もう1つの賢明なアイデアは、プレーヤーがマップの端に近いときにオンデマンドでブロックを生成することです。これにより、読み込み時間が短縮されます。