I have a constructor, Chomp
, which creates a canvas element; its property that has the canvas element is this.c
, but when I try to call functions on this.c
in a method of my constructor, I receive an error: TypeError: Cannot read property 'beginPath' of undefined (line 28 in function Chomp.chomping)
. I need to know why this is and how to fix this problem. Below is the part of my code important to this problem.
var Chomp = function(x, y) {
/*many properties*/
this.c = this.element.getContext("2d");
/*a few more properties*/
}
Chomp.prototype.chomping = function() {
/*some conditions,... properties like this.width were defined in Chomp,
but omitted because of their lack of importance to the question.*/
this.c.clearRect(/*arguments*/);
this.c.beginPath();
this.c.moveTo(/*arguments*/);
this.c.arc(/*arguments*/);
this.c.lineTo(/*arguments*/);
this.c.lineTo(/*arguments*/);
this.c.fillStyle = "yellow";
this.c.fill();
/*more conditions*/
}
Thanks ahead of time! :)
Aucun commentaire:
Enregistrer un commentaire