我目前正在學習如何在可汗學院編碼javascript。我正在研究fish tank project
。mouseClicked不能用if語句來調用函數
代碼:
background(89, 216, 255);
var centerX ;
var centerY ;
var bodyLength = 118;
var bodyHeight = 74;
var drawFish = function(centerX, centerY) {
noStroke();
fill (random(1,255), random(1,255), random(1,255));
// body
ellipse(centerX, centerY, bodyLength, bodyHeight);
// tail
var tailWidth = bodyLength/4;
var tailHeight = bodyHeight/2;
triangle(centerX-bodyLength/2, centerY,
centerX-bodyLength/2-tailWidth, centerY-tailHeight,
centerX-bodyLength/2-tailWidth, centerY+tailHeight);
// eye
fill(33, 33, 33);
ellipse(centerX+bodyLength/4, centerY, bodyHeight/5, bodyHeight/5);
};
if(mouseClicked) {
drawFish(random(1,400), random(1,400)); } else { text ("Left click to add fish!", 100, 100); }
它的工作原理,如果我只是調用的函數多次與複製和粘貼,但我想它,如果我點擊了屏幕上工作。我也試過它也與mousePressed
和mouseIsPressed
。
是什麼 「的mouseClicked」 ???在哪裏設置??? ???可能是有用的看到你的完整代碼 – lem2802
CODE:mouseClicked = function(){ drawFish(random(1,400),random(1,400));};這樣可行。 –