我最近使用P5做出笨鳥先飛喜歡的遊戲,直到一個小時前我曾經定義和調用我的對象我這樣的比賽:我的for循環中創建對象的心不是工作名爲.js與P5
function setup(){
//**Define**
cloud1 = new Cloud(random(100, windowHeight - 500), random(0.7, 1.3));
cloud2 = new Cloud(random(100, windowHeight - 500), random(0.7, 1.3));
};
function draw(){
//**Draw Clouds**
cloud1.show();
cloud2.show();
};
這工作得很好,但是當我試圖以下列方式使用for循環:
function setup(){
//**Define**
for(var i = 0; i < 5; i++) {
cloud[i] = new Cloud(random(100, windowHeight - 500), random(0.7, 1.3));
}
}
function draw
//**Draw Clouds**
for(var i = 0; i < 5; i++) {
cloud[i].show();
}
}
調試器說,我的「雲」的對象的心不是定義。我以前用過類似的方式使用過這種代碼,沒有任何問題。誰能幫我?
對不起,我的英語不好。
你在哪裏定義'cloud'變量? –
相關:https://stackoverflow.com/questions/1470488/what-is-the-purpose-of-the-var-keyword-and-when-to-use-it-or-omit-it –