p5.js不加载我的椭圆

问题描述:

我想绘制一个椭圆模拟一只鸟在飞扬的鸟。 我绘制的椭圆不加载到我的屏幕上我检查了我的语法与p5网站,它看起来很好。p5.js不加载我的椭圆

我有2个文件bird.js和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); 
    } 
} 

很奇怪的是,这是行不通的,但与对象的其他语法,它的工作:

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