function component(width, height, source, x, y) {
this.image = new Image();
this.image.src = source;
this.width = width;
this.height = height;
this.x = x;
this.y = y;
this.update = function() {
ctx = myGameArea.context;
ctx.drawImage(this.image,
this.x,
this.y,
this.width, this.height);
}
this.newPos = function(a, b, image, h) {
this.x = a;
this.y = b;
this.image.src = image;
this.height = h;
}
}
Wie rufe ich eine Funktion auf, wenn ein Klick auf die Komponente ausgeführt wird? Oder sollte ich einfach die Koordinaten des Klicks aufzeichnen und sie mit denen der Komponente vergleichen?Wie ruft man eine Funktion bei einem Klick auf eine Komponente auf?