相关疑难解决方法(0)

在画布中随机生成对象,不会重复或重叠

如何在地图上生成对象,而不占用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)

javascript arrays html5 canvas

3
推荐指数
1
解决办法
7776
查看次数

标签 统计

arrays ×1

canvas ×1

html5 ×1

javascript ×1