vendredi 3 juillet 2015

mouseClicked not working with if statement to call a function

i'm currently learning how to code javascript on khan academy. Im working on the fish tank project. Here's the code.

 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); }

It works if i just call the functions loads of times with copy and paste but i want it to work if i click the screen. I have tried it also with mousePressed and mouseIsPressed. Thanks!!!

Aucun commentaire:

Enregistrer un commentaire