如何在地图上生成对象,而不占用HTML5 Canvas上的相同空间或重叠?
在某种程度上随机生成X坐标.我想在数组内查看它是否已经存在,然后是接下来的20个值(考虑到宽度),没有运气.
var nrOfPlatforms = 14,
platforms = [],
platformWidth = 20,
platformHeight = 20;
var generatePlatforms = function(){
var positiony = 0, type;
for (var i = 0; i < nrOfPlatforms; i++) {
type = ~~(Math.random()*5);
if (type == 0) type = 1;
else type = 0;
var positionx = (Math.random() * 4000) + 500 - (points/100);
var duplicatetest = 21;
for (var d = 0; d < duplicatetest; d++) {
var duplicate = $(jQuery.inArray((positionx + d), platforms)); …Run Code Online (Sandbox Code Playgroud)