I just started a tutorial in game development using JavaScript and HTML5. javascript.prototype has come into play many times. I can not really understand how it works. Here is a link I found with a good explanation, but I am still a little bit confused
How does JavaScript .prototype work?.
Can anyone explain this please? Here is an example of my code:
function Enemy(){
this.srcX = 140; //gets the location of enemy in x and Y here
this.srcY = 600;
this.width = 45;//gets the enemies width and height here
this.height = 54;
this.drawX = randomRange(0, canvasWidth - this.width);
this.drawY = randomRange(0, canvasHeight - this.height);
this.centerX = this.drawX + (this.width / 2);
this.centerY = this.drawY +(this.height / 2);
//this.targetX = this.centerX;
//this.targetY = this.centerY;
//this.randomMoveTime = randomRange(4000,10000);
this.speed = 1;
//var that = this;
//this.moveInterval = setInterval(function() {that.setTargetLocation();},that.randomMOveTime);
this.isDead = false;
}
Enemy.prototype.update = function() {
//this.checkDirection();
this.centerX = this.drawX + (this.width / 2);
this.centerY = this.drawY + (this.height / 2);
}