phaserjs / phaser-ce

Phaser CE is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
http://phaser.io
MIT License
1.34k stars 491 forks source link

In several cases,Group.callAll() will not work or make errors #662

Closed aleafworld closed 4 years ago

aleafworld commented 4 years ago

Not sure if this is a bug: eg. sprites in group have a method as "sprite.subobj.func()" group.callAll("subobj.func") ---- not work group.callAll("func","subobj") ---- not work group.callAll("subobj.func","subobj") ---- it work

the API ---- "callAll(method, context, args)" don't you think the second paramater is unnecessary?

samme commented 4 years ago

Assuming you want to do

sprite.subobj.func.call(sprite.subobj);

then only these arguments are correct:

group.callAll("subobj.func", "subobj");

The default context is always sprite, no matter what you pass in method. It's true that if you pass a deep property in method you will probably have to pass a matching context as well, I guess the docs could note that.

samme commented 4 years ago

https://samme.github.io/phaser-examples-mirror/groups/call%20all%20animations.html

aleafworld commented 4 years ago

Thanks. I think context can be removed, because it can get by

context = methodLength > 1 ? this.callbackFromArray(child, method, methodLength - 1) : child;

then the code will be simpler.

samme commented 4 years ago

Closing since it works as described.