Jump to content

Getting the name of an object "class"


Recommended Posts

Hello, I'm trying to define a few objects with their names + properties using classes.

I can have new Goals at creation, however I'm stuck with prototypes.

So far it's:


//***************** OBJECTSfunction Goal(nombre, posX, posY){	this.nombre = nombre;	this.posX = posY;	this.posY=posY;	//console.log ('nombre: '+ this.nombre+ ' pos x: '+this.posX);	this.sp = game.add.sprite(posX,posY, 'bola');	game.physics.enable(this.sp, Phaser.Physics.ARCADE);	this.sp.body.immovable = false;    this.sp.body.collideWorldBounds = true;    this.sp.body.bounce.setTo(1, 1);	this.sp.inputEnabled = true;	this.sp.events.onInputDown.add(listener1, this);		/*this.listener1 = function(){		console.log (this.name + 'was cliked!');	}*/}Goal.prototype.listener1 = function() {	console.log (this.name + 'was cliked!');}

My goal was to know which object was clicked (using listener1).

I get a console message:

ReferenceError: listener1 is not defined

Thanks for the patience and the advice on how to fix this.



Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...