Ryzon
Ryzon

Reputation: 9

p5.js is not loading my ellipse

I am trying to draw an ellipse to simulate a bird in flappy bird. The ellipse i am drawing is not loading onto my screen I have checked my syntax with the p5 website and it looks fine.

I have 2 files bird.js and sketch.js.

Sketch.js:

 var bird;
    function setup() {
        createCanvas(400, 600);
        bird = new Bird();
        console.log(bird.show);
    }

    function draw() {
        background(255, 0, 255);
        bird.show;
    }

bird.js:

function Bird() {
    this.y = 300;
    this.x = 100;

    this.show = function() {
        fill(255, 255, 255);
        ellipse(this.x, this.y, 16, 16);
    }
}

Upvotes: 0

Views: 686

Answers (2)

v624mpi
v624mpi

Reputation: 11

You forgot to put parentheses for the bird.show‌():

var bird;
function setup() {
    createCanvas(400, 600);
    bird = new Bird();
    console.log(bird.show);
}

function draw() {
    background(255, 0, 255);
    bird.show(); //corrections 
}

Upvotes: 1

HReynaud
HReynaud

Reputation: 54

It's strange that it doesn't work, but with an other syntax of the object it's working :

var Bird = {
  init : function(){
    this.y = 300;
    this.x = 100;
  },
  show : function() {
   fill(255, 255, 255);
   ellipse(this.x, this.y, 16, 16);
  }
}
var bird=Bird;
function setup() {
  createCanvas(400, 600);
  bird.init();
  //console.log(bird.show);
}
function draw() {
  background(0, 0, 0);
  bird.show();
}

Upvotes: 0

Related Questions