2017-05-03 47 views
0

我想繪製一個橢圓模擬一隻鳥在飛揚的鳥。 我繪製的橢圓不加載到我的屏幕上我檢查了我的語法與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); 
    } 
} 

回答

0

很奇怪的是,這是行不通的,但與對象的其他語法,它的工作:

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