UPDATE: Find the code here: http://pastebin.com/Gv0rqMaF (thanks to chinmay.patil for doing that!).
New features in the lastest version (0.2):
-
External custom transition libraries.
-
Custom transitions are easier to write now.
-
Major internal re-jigging of how it all works (more as an exercise than anything else!).
-
Far too much disorganised help text!
I’ve spent the last week writing my own routines to duplicate (and for my needs, improve) code libraries already available - mostly as a learning exercise.
In the case of scene/module changing, although I wrote my code from scratch, it was based heavily on Director for many areas.
Although my own code isn’t finished, I’m posting it here firstly as a way of saying ‘thank you’ to whoever wrote Director, and also to show some additional features / transitions I’ve put / am putting in, in case someone wants to roll these ideas into the director code.
Despite the thread title, I’m not setting myself up in competition with director, I just thought it might be fun to see what people think of my early efforts.
How to use:
scenes = require("scenes")
Is the minimum, but it also has an initialise() routine, which you can use to alter most of the default properties. This is the easiest way of setting the default transition time, for example, and also returns the top-level display group used by the module. For example:
scenesGroup = scenes.initialise{ fadeBG = true, transitionTime = 500, defaultTransition = "zoomBothHide" }
Anyway, here’s the things it does, possibly differently to Director:
- Windowed usage. Pass a rectangle table { x=, y=, width=, height= } etc when you initialise and it should treat that rectangle as the visible area. Note you’ll have to manually clip the area if you plan on using transitions that go outside this area (which is most of 'em!).
- Ability to not need a static background on each scene. This is what the fadeBG value is for. When set to true, whichever scene is behind during the transition will fade its alpha out to zero at the same time.
- Ability to hook into 4 function calls automatically within your modules - new() which is required and must return the scene’s local group, but also wake(), sleep() and destroy(). Wake is called in the new scene when the transition has finished. Sleep() is called in the old scene when the transition begins, and destroy is called in the old scene when the transition finishes
- Ability to not unload a scene when its finished being used. To achieve this, you must return false from the destroy() routine in the scene - this tells the code to not do anything. However, this means you are now responsible for cleaning up the group. What I do is in the destroy() function is move that scene’s local group to another, storage group (that is offscreen and invisible).
- Prevents touch events from triggering during the transition itself. IE you can’t touch buttons etc while they are mid-transition. It does this by having a visible (but with alpha = 0) rectangle that covers the window, that swallows these events.
- Custom transitions. You can pass a function instead of a transition name. This function will be called at the appropriate time, along with a params table containing all the information you need from the scenes module. There’s an example in the help text of the module itself.
- Passing parameters to new(). If you do scenes.useScene(“blah”, “fade”, { wib="wob }) then the table will be passed to new() as a parameter.
- Random parameters. Choose from any random, or just random within a group. Look in the useScene() function for individual transition names and random groups.
- my own slight tweak to cleanGroups() (I read the thread about its problems the other day!).
There’s likely a few other things I forgot, but the code isn’t really long, and those of you familiar with director will likely have no problems getting to grips with it.
Again - this isn’t a competitor to Director, its more a homage.
Enjoy!
Barry
PS Oooh finally found the first post edit button, now why isn’t it in the same place as for all the other posts? :s
[import]uid: 46639 topic_id: 9362 reply_id: 309362[/import]