Ninjadoodle Posted June 27, 2014 Share Posted June 27, 2014 Hi guys I can't quite figure out how to do a global function in PandaJS. I know you can add global variables by doing 'game.yourVariable', but can't seem to do the same with functions. I've had a look at classes, but I'm not sure, they are what I need. All I need is a reusable piece of code, that I can call later in any scene/level I choose. I have a basic function working ... game.nextLevel = function () { // Do something} But, what if I want to address variables that have not been declared yet? The reason I ask is - I have a whole bunch of items I want to add at the start of each level.Is there an easy way to lets say add all HUD items etc. without having to recreate them on each level init? Any ideas would be awesome Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted July 3, 2014 Author Share Posted July 3, 2014 Hi Guys I still can't figure this one out. Basically, I have a whole bunch of code sitting in my init: function() I want to reuse the same code as a basic level/hud setup and I don't want to paste the same code into 20 level files. Is there any way I can include a snipped inside a .js file or make a reusable code function? Thanks again Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted July 4, 2014 Author Share Posted July 4, 2014 Got it! It was all about referencing stuff correctly. I had some code within the class using 'this.stage' instead of 'game.scene.stage' Now it works flawlessly pinkpanther 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.