In Instance Mode, how do I write events function ?

In Instance Mode, how do I write events function ? For example, I do not know how to write "mousePressed" in this code (Instance Mode): This is not explained in this reference page: http://p5js.org/learn/examples/Instance_Mode_Instantiation.php

  var sketch1 = function( p ) {
  var x = 100; 
  var y = 100;
  var myColor = 127;
  p.setup = function() {
    p.createCanvas(700, 410);
  };

  p.draw = function() {
    p.background(0);
    p.fill(myColor);
    p.rectMode(p.CENTER);
    p.rect(p.mouseX,p.mouseY,50,50);
  };
    
  //HERE !!! HERE !!! HERE !!! HERE !!! HERE !!! HERE !!! HERE !!! :
  //  p.mousePressed = function() {... ???
  //  p.mousePressed() = function() {... ???
  //  mousePressed = p.function() {... ???
 };

Answers

Sign In or Register to comment.