I want a parameter of one of my classes to be a function that will be particular to an instance of that class. In this case I have a sprite class, I want different "onCollide" functions to be called for different instances of this class. Here is what I have coded.
function StaticSprite(tileset, x, y, onCollide) {
this.tileset = tileset;
this.x = x;
this.y = y;
this.onCollide = onCollide;
}
var introSign = new StaticSprite(mainTiles, 800, 600, showMessage('Hi.'));
if (isColliding(player, introSign)) {
introSign.onCollide();
}
This code obviously doesn't work but should at least show what I'm trying to achieve. Thanks.