The properties x,y,width,height
are not being read! When I do .drawImage()
, this.x, this.y, this.width, this.height
are not being used!
Say I changed the x
the image won't change its position. However, if I alert(this.x)
or any variable, then it will print out the correct value.
Thanks for the community help!
var Enemy = function(word, x, y, width, height) {
this.word = word;
//Position of the Enemy Spawn
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
Enemy.prototype.draw = function() {
var image = new Image();
image.onload = function() {
Context.context.drawImage(image, this.x, this.y, this.width, this.height)
};
image.src = "enemy.png"
// If I do alert(this.x), it returns the correct value!!!
}
This is the initialization:
var myEnemy = new Enemy("TestEnemy", 100, 100, 100, 100);
myEnemy.draw();