Jump to content

Getting the current scene name


ambidex
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);        }    });
Link to comment
Share on other sites

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);...}
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...