我一直在关注如何在 HTML5 中制作简单游戏的本教程,我遇到了一个我无法理解的参数的有趣用法......这里作者使用单个参数 I 创建了一个名为 Bullet 的构造函数,但是看他如何使用我。这是怎么回事?我不明白:
function Bullet(I) {
I.active = true;
I.xVelocity = 0;
I.yVelocity = -I.speed;
I.width = 3;
I.height = 3;
I.color = "#000";
I.inBounds = function() {
return I.x >= 0 && I.x <= CANVAS_WIDTH &&
I.y >= 0 && I.y <= CANVAS_HEIGHT;
};
I.draw = function() {
canvas.fillStyle = this.color;
canvas.fillRect(this.x, this.y, this.width, this.height);
};
I.update = function() {
I.x += I.xVelocity;
I.y += I.yVelocity;
};
return I;
}