果實(shí)出不來
var fruitObj = function() {
this.alive = []
this.x = []
this.y = []
this.orange = new Image()
this.blue = new Image()
}
fruitObj.prototype.num = 30
fruitObj.prototype.init = function() {
for(var i = 0; i < this.num; i++) {
// 定義果實(shí)生命期為true,說白了就是顯示
this.alive[i] = true
this.x[i] = 0
this.y[i] = 0
// 遍歷30次,分別得到這30次果實(shí)的位置
// this.born(i)
}
this.orange.src = "./src/blue.png"
this.blue.src = "./src/fruit.png"
}
fruitObj.prototype.draw = function() {
for(var i = 0; i < this.num; i++) {
// 繪制果實(shí)的圖片以及位置
ctx2.drawImage(this.orange, this.x[i] - this.orange.width * 0.5, this.y[i] - this.orange.height * 0.5)
}
}
fruitObj.prototype.born = function(i) {
// ane.num == 50
var aneID = Math.floor(Math.random() * ane.num)
// 使每個果實(shí)的橫坐標(biāo)對應(yīng)每個??臋M坐標(biāo)
this.x[i] = ane.x[aneID]
// 使每個果實(shí)的縱坐標(biāo)剛好在每個??纳厦?/p>
this.y[i] = canHeight - ane.len[aneID]
}
2019-09-23
你第16行的this.born(i)被注釋掉了