How to use objects in instance mode ?

okay. So , its simple. I can´t find reference of how to create an object in instance mode.

Is it possible ? How is it doned?

This is my code and what ive tryed so far :

function Ball(x,y) {
    this.x = x;
    this.y = y;
    this.xspeed = 1;
    this.yspeed = 1;

    this.display = function(){
        stroke(20);
        strokeWeight(1);
        noFill();
        ellipse(this.x,this.y,20,20);
    }

    this.move =  function() {
        this.x = this.x +this.xspeed;
        this.y = this.y + this.yspeed;
    }

    this.bounce = function () {
        if (this.x > width || this.x < 0){
            this.xspeed = this.xspeed * -1;
        }
        if (this.y > height || this.y < 0){
            this.yspeed = this.yspeed * -1;
        }
    }
}
//CANVAS 2
var sketch2 = function(can2){

    can2.Paints = [] ;
    can2.i;
    can2.a = 50;

    can2.Ball(30,30) ;
   can2.setup = function () {
        can2.createP ('Canvas2');
       can2.createCanvas(300, 300) ;
   };
   can2.draw = function () {

    can2.background('#F0F');
        can2.bebito.display();
   };

};

new p5(sketch2, 'canv2');
Tagged:

Answers

Sign In or Register to comment.