Jump to content

Overriding 'create' function in Phaser.Group


FriarBabs
 Share

Recommended Posts

Can the 'create' function in Phaser.Group be successfully over-ridden? Is there an alternative?

 

I am looking for a way to have a function called at the start of my object's life-cycle and still be able to access the functions I have built into the class. I am used to Unity3D where there is always an option to do this.

 

There is certain code that I need to execute at the start of my object's life-cycle, and additionally whenever the level ID is set in my function.

 

Am I being clear, or have I worded this too confusingly? Thanks much!

FriarDude.FallingShitFactory = function (game) {	// Class variables	this.levelID = 0;	this.active = false;	this.spawnTimer = null;	this.percentShitQuantities = new Array();	this.HORIZONTAL_MARGIN = 64;	//	// The constructor can take an optional parameter (levelID, 0 by default)    if (arguments.length == 2) {    	this.levelID = arguments[1];    }	//	// Constructor	Phaser.Group.call(this, game);	game.time.events.loop(1000, this.spawnShit, this);	console.log('construct');    return this;    //};FriarDude.FallingShitFactory.prototype = Object.create(Phaser.Group.prototype);FriarDude.FallingShitFactory.prototype.constructor = FriarDude.FallingShitFactory;FriarDude.FallingShitFactory.prototype.create = function() {	// Load Level Data	console.log('create');	this.setLevelID(this.levelID);	//}
Link to comment
Share on other sites

This is the correct answer for the info that I provided. I was a real dummy and didn't realize that I wasn't actually creating an object in my group, which activates the 'create' method for the group.

 

Is there a method that is called when the Group itself is added to the scene?

 

EDIT: I fixed my issue. 'Constructors' in JS's prototypical inheritance pattern are fake, methods within the prototype can still be accessed from within the constructor. That was my overall goal.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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