Zampano

Extending Phaser functions

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.

Share this post


Link to post
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 ...
};

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.