产卵精灵与for循环

时间:2014-11-18 21:41:57

标签: javascript jquery html5 for-loop html5-canvas

我无法在画布的随机位置产生相同精灵的倍数。 var =障碍是我正在谈论的那个。我们试图用for循环来做这件事。请帮帮忙?

Jsbin链接:http://jsbin.com/warurijuji/2/edit

代码不起作用:

//Uploading obstacle image
var obstacle = new Image();
obstacle.src = "http://2.bp.blogspot.com/-dE5my5trgGU/TyQ4ULWlXhI/AAAAAAAABTE/lD1Al2Vql1c/s320/cartoon+pineapple+clipart.png";

//for loop for spawning it
function drawObstacle() {

  for (i = 0; i <= 50; i++) {

          var x1 = Math.floor(Math.random() * 299);
          var y2 = Math.floor(Math.random() * 299);

          context.fillStyle = "#EEEEEE";

          if (x1 > 40 && y2 > 40) {

            context.beginPath();
            context.arc(x1, y2, 3, 0, Math.PI * 2, true);
            context.closePath();
            context.fill();
          } else--i;
        }
  }

0 个答案:

没有答案