dthrasher90 Posted April 13, 2017 Share Posted April 13, 2017 Hey guys, quick question... hopefully. So I have a sprite in one function with x,y coordinates, I am trying to pass to another function. Im essentially using this sprites position to align others. How do you accomplish this? The only caveat is that function B is located in another file, its just being invoked in functionA. So Like: function A (){ //lots of stuff game.add.sprite = sprite1(some.x, some.y) B(); } functionB (){ game.add.sprite= sprite2(sprite1.x, sprite1.y); } Link to comment Share on other sites More sharing options...
FakeWizard Posted April 13, 2017 Share Posted April 13, 2017 the js file where you have the function B defined has to be loaded before the other file where you;re using it. /// fileA.js function A (){ game.add.sprite = sprite1(some.x, some.y) B(); } /// fileB.js function B (){ game.add.sprite= sprite2(sprite1.x, sprite1.y); } So in your index.html file you just do <script src="fileB.js"> </script> <srcipt src="fileA.js"> </script> Link to comment Share on other sites More sharing options...
Aquarius Posted April 13, 2017 Share Posted April 13, 2017 Not fan of this way of coding, because you never know wich script will be executed first. I think that a better way is to have a function that will execute function B, then A. function process(){ A(); B(); } Link to comment Share on other sites More sharing options...
Recommended Posts