pass argument to callMethod

15 views
Skip to first unread message

Rosanqodrian Nurfikri Soffian

unread,
Feb 8, 2016, 1:54:52 AM2/8/16
to excaliburjs
is it possible to pass arguments to callMethod's function?, something like

callMethod((arg1, arg2) => {
  ...
}, arg1, arg2, ...);

Kamran Ayub

unread,
Feb 8, 2016, 1:36:07 PM2/8/16
to excaliburjs
Hey here,

Depending on what you're doing, you shouldn't need to... the callMethod action is just part of the Action chaining, so it will be called in order. If you need access to anything outside the scope of the function, you can just reference the variable name.

For example:

var actor = new ex.Actor(...);

// move the actor and then kill it when it's done moving
actor.moveTo(x, y, 200).callMethod(() => actor.kill());

If you need more explanation, it'd be helpful to see a snippet of what you were trying to do.

Kamran Ayub

unread,
Feb 8, 2016, 1:45:27 PM2/8/16
to excaliburjs
One more thing I should add, by default, the "this" context will be the current actor, if you use function syntax. Lambda syntax will bind the outer scope to "this", not the actor.

.callMethod(function () {
  this // will be actor
});

so my prev example could be:

actor.moveTo(x, y, 200).callMethod(function () { this.kill(); });

would work too, without referencing outer scope variables.


On Monday, February 8, 2016 at 12:54:52 AM UTC-6, Rosanqodrian Nurfikri Soffian wrote:
Reply all
Reply to author
Forward
0 new messages