I am currently hard coding 10 different instances like the code below, but but I'd like to create many more. Instead of having the same layout for the new level, I was wondering if there is anyway to generate a random X value for each block (this will be how far into the level it is). A level 100,000 pixels wide would be good enough but if anyone knows a system to make the level go on and on, I'd like to know that too. This is basically how I define a block now (with irrelevant code removed):
block = new Block(R.drawable.block, 400, platformheight);
block2 = new Block(R.drawable.block, 600, platformheight);
block3 = new Block(R.drawable.block, 750, platformheight);
The `400` is the X position, which I'd like to place randomly through the level, the `platformheight` variable defines the Y position which I don't want to change. A for loop and some Math.random() calls. Did you try googling for it...
以上就是How do I generate a level randomly?的详细内容，更多请关注web前端其它相关文章！