嗨,大家好我再次遇到了我的遊戲代碼中的一個缺陷......所以我在這裏試圖在我的「Player Rocket」中添加這個代碼這本書只是讓我在我所有生成的小行星下面添加。Uncaught TypeError:無法設置undefined的屬性'vX'
player.vX = 0;
player.vY = 0;
if (player.moveRight) {
player.vX = 3;
};
if (player.moveUp) {
player.vY = -3;
};
if (player.moveDown) {
player.vY = 3;
};
player.x += player.vX;
player.y += player.vY;
context.fillStyle = 'rgb(255, 0, 0)';
context.beginPath();
context.moveTo(player.x+player.halfWidth, player.y);
context.lineTo(player.x-player.halfWidth, player.y-player.halfHeight);
context.lineTo(player.x-player.halfWidth, player.y+player.healfHeight);
context.closePath();
context.fill();
現在的錯誤我不斷收到這本...
Uncaught TypeError: Cannot set property 'vX' of undefined
我通過這本書看了看,如果我有一些定義這個地方,但我沒有錯過任何東西。現在,我仍然是新的這個,但唯一的地方,我看到我使用player.vX
在這裏。
var player;
var Player = function(x, y){
this.x = x;
this.y = y;
this.width = 24;
this.height = 24;
this.halfWidth = this.width/2;
this.halfHeight = this.height/2;
this.moveRight = false;
this.moveUp = false;
this.moveDown = false;
this.vX = 0;
this.vY = 0;
};
如果有人能幫助我,並更好地理解這將是偉大的!謝謝!!!
? – Misters
如果該代碼來自一本書,請將該書從您的窗口中移出並找到另一本。 – adeneo
你可以把它張貼在小提琴上,所以我們可以直接看到所有這些帆布事情的錯誤?謝謝 – xhallix