Jump to content

Extending Phaser functions


Zampano
 Share

Recommended Posts

Hey everyone,

I want to attach some additional code to Phaser.Tween.start.

I realize I could do

Phaser.Tween.prototype.start_custom = function () {
	console.log("Custom Code");
	Phaser.Tween.prototype.start.call();
}

But couldn't I also do it without creating a separate function? I can't find anything really helpful on it and although I realize it's pretty basic, I have no idea on how to actually do it :D

Any help is greatly appreciated.

Link to comment
Share on other sites

One is just to copy and modify the original function body, then overwrite the function:

Phaser.Tween.prototype.start = function () {
  // ...
};

Another is to save the original and call it from the new function:

var tweenStart = Phaser.Tween.prototype.start;

Phaser.Tween.prototype.start = function () {
  // special code ...
  tweenStart.call(this);
  // special code ...
};

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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