ambidex Posted October 16, 2014 Share Posted October 16, 2014 I've got an application which will show an scene that functions as a screensaver on a few seconds idle time. Though that works perfectly, I can't seem to get the current scene name that is running (to switch back to it when the system activates). I would've thought that would be as easy as 'game.scene.name' or something like that. But the scenes do not seem to contain their own name. I already tried extending the Scene class and implementing my own staticInit func, but getting the name even from there seems virtually impossible. Also I tried creating my own createScene function and passing the name to the scene that is created but also on that level I can't seem to figure out how to pass the name variable to the eventual scene. Any ideas? Edit: Ofcourse I could track the name by using a helper function that switches the scenes and storing the name globally, but this seems more like a workaround then a actual solution for such a simple variable. Quote Link to comment Share on other sites More sharing options...
Stephan Posted October 16, 2014 Share Posted October 16, 2014 Adding a name to a specific Scene class shouldn't be too difficult. The thing is, while you are running the screensaver, it is the only scene running at that particular moment to retreive an name from. So this wouldn't work. So I think that you are talking about transfering data from the running scene to the next scene that is being started? Quote Link to comment Share on other sites More sharing options...
ambidex Posted October 16, 2014 Author Share Posted October 16, 2014 Yeah, my current workaround which I was forced to use till now is creating a helper function which does only fire the "game.system.setScene" function and saves the called scene name into a globally accessible variable. This works fine, though seems a bit of a weird workaround. Shouldn't the current scene (living in game.scene) know it's own name? Might be entirely wrong, but this seems to be a small addition to the core code to make, if it isn't already available. Then you'd be able to find the name anywhere by just calling: game.scene.name. Quote Link to comment Share on other sites More sharing options...
Stephan Posted October 16, 2014 Share Posted October 16, 2014 I have had a lot of problems with transfering data in impactJS before in the past. I remember that I ended up with some dirty global which was not very satisfactory. I will have a look at this problem the next few days because I definitively want to have this sorted out before I start my next project. Perhaps I'll write a small plugin or a codefix for the engine. Quote Link to comment Share on other sites More sharing options...
ambidex Posted October 16, 2014 Author Share Posted October 16, 2014 This is my current workaround, a game.system module which will consist more then only this workaround. It contains the following GameSystem class. By using this class' setScene instead of the built-in function, I'm able to fetch the current scene's name by using: game.system.currentSceneName. I don't like hacking core files so I always try to use workarounds which stay inside my local game files. game.createClass('GameSystem', { init: function () { game.system.currentSceneName = 'Main'; }, setScene: function (sceneName) { game.system.currentSceneName = sceneName; game.system.setScene(sceneName); } }); Quote Link to comment Share on other sites More sharing options...
enpu Posted October 17, 2014 Share Posted October 17, 2014 Hi guys! I have added new property currentSceneName to System on develop branch. So you should be now able to get current scene name with:game.system.currentSceneName Quote Link to comment Share on other sites More sharing options...
ambidex Posted October 17, 2014 Author Share Posted October 17, 2014 Awesome enpu, thanks again! Quote Link to comment Share on other sites More sharing options...
Stephan Posted October 20, 2014 Share Posted October 20, 2014 Hi ambidex and enpu, I just made a pull request for the development branch for a new option that allows direct data transfer between different scenes.It works like so: //in Scene1:game.system.setScene('Scene2', {message1: 'This text is transferred to scene 2'});//in constructor of Scene2:init: function(options) {console.log(options.message1);...} Quote Link to comment Share on other sites More sharing options...
enpu Posted October 20, 2014 Share Posted October 20, 2014 Hi Stephan, Thanks for the pull request, though i'm not sure if it's really necessary add.Can you give me an example, where you would need that?You can always make global objects/variables in game namespace to transfer data between scenes? Quote Link to comment Share on other sites More sharing options...
Stephan Posted October 20, 2014 Share Posted October 20, 2014 In the past I have developed complex apps in impactJS where I needed this feature quite frequently. (If you want to see some of my previous work, check out 'math blobs' in the appstore). I had a couple of scenes with seperate educational games That could be played with different content. In the main menu one could select the content and I had to pass in on with a global. Of course this worked fine but it felt like a really ugly solution. It's like passing data to a function with globals instead of arguments.I must say that I am not sure how many people will actually use this a lot in addition to myself (although the ajustment is quite light weighted). Of course it's up to you if you want to include this in the main panda development. 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.