Finding current screen 'number' - for 'next', 'prior', and other computed transitions

I love the whole framework of director class - and just learning how it all works. Sorry if I’ve missed something - but I can’t quite see how to implement a transition to ‘next screen’ (say, when I’m on screen5).

I don’t want to hardcode a transition to 'screen6…would rather be able to use the current screen number(5), check if there’s a ‘next’ screen in my envt, and, if so, transition to it.

Thanks for any insight about that - it’d really open up the usefulness of director class for me.

[import]uid: 34130 topic_id: 7890 reply_id: 307890[/import]

In the meantime - I did find a pretty easy way to add what I wanted to director class:

  • added a global ‘screenNumber’ to director.lua, keeping a simple numeric index for the current screen
  • 'getScreenNumber() and setScreenNumber(n) functions to manage that current screen numeric value
    -simple string split logic inserted in changeScene(), where it’s easy to pick a number off the end of the string ‘nextLoadScene’.
    Actually, I changed my filenames to ‘screen-1’ screen-2, etc. to make it even easier to pick the number from the end.

I might still have missed an easier way, and would be interested to learn about it – but at least it wasn’t hard to get something working. Now I can have ‘prior’ and ‘next’ screen logic, [import]uid: 34130 topic_id: 7890 reply_id: 28079[/import]

What I do, is add a property to the button that defines which scene that particular button goes to, like this:

local playButton = display.newImageRect();  
playButton.scene = "Game";  
  
local backButton = display.newImageRect();  
backButton.scene = "LevelSelect";  

And my listener function looks like this:

function ChangeScene(e)  
 if(e.phase == "ended") then  
 director:changeScene(e.target.scene, "crossfade");  
 end  
end  
  

This assume the playButton and the backButton only ever have one target, in that the backButton from this particular screen can only ever go to ONE SPECIFIC scene. I guess if you wanted the buttons to go to different scenes in different situations, you could do that by handling the necessary switching of the object.scene property based on other conditions… [import]uid: 5317 topic_id: 7890 reply_id: 28627[/import]