Corona Geek #128 - Custom Transitions and Functions

At around 24mins of this presentation on Custom Composer Transitions, Ed mentions an example he has seen where someone used custom functions that were called as the transition updated its values.

This is something that might help our current challenge to fade up a black rectangle just as the first scene is fading out. Any chance there is an example online to shed more light on how this might be achieved?

Many thanks.

https://coronalabs.com/blog/coronageek/composer-library-series-hangout-highlights/

Hi.  Pretty much all the code I’ve written for the Corona Geek hangouts is here:

http://github.com/roaminggamer/CoronaGeek

The composer stuff is here:

Hey Ed, many thanks for the links, good stuff.

The question I have pertains to a comment you made on Corona Geek where you had seen a “really cool example the other day where someone made not a custom transition… but they could substitute their own function as a transition…”

This is something we’ve thought of doing, so for instance, if a scene transition is fading out, have a runtime listener on the sceneGroup’s alpha and then trigger another function to coincide with that…

Anyway, if you can remember where you saw this example, it would be most useful to understand how someone has done this.

Here is a URL of the episode at the time in question:

https://youtu.be/Ht8iSJ8uBms?t=1430

Thanks.

I’m afraid I don’t remember an exact thread link from over 7 months ago.  :blink:   
 
I did however include links to sources in the code:

If I understand what you’re trying to do, you should be able:

  1. Write your own easing.
  2. Insert it into the easing library. (similar to how I added custom transitions to composer, but for easing.* instead)
  3. Use it in a custom scene transition. (again the samples provided show how to code your own, insert, and use it)

That’s about all I can say.  Sorry, but my memory just isn’t that good.

PS - This is what I mean by #1 and #2 above (assume the following is in file customeasing.lua)

local function linear(t, b, c, d) return c \* t / d + b end easing.myLinear = linear

Once you require “customeasing”, the easing library should now have a new easing called ‘myLinear’. (Totally untested but I think this is right.)

Yet more (possibly useful) links:

Oh, and you can change easing linkages at any time.  i.e. If you needed to, you could replace easing.myLinear right before using it.

Finally, there are two more options:

  • enterFrame listener (I think you meant this, not Runtime) - Watching a value and acting when that value reaches a trigger point).
  • Advanced lua coding, wherein you modify the __index metamethod, etc. functions of the scene. (I’m sure there was a blog post here about that, so you might want to page through them to find it (only 158 pages of blog posts :slight_smile:http://coronalabs.com/blog/page/158/))

Thanks again Ed. Yes, it was your last number 2 point that I was looking for a working example - “Watching a value and acting when that value reaches a trigger point”. An enterFrame listener it is. Though we are using a one page, dynamically generated version of Composer which does add a level of difficulty reaching the scene.view… Anyway, will post the results if they add anything to the Composer effectsLIst conversation.

If you’re trying to generate the content in the scene, but want the scene to do transitions, you might use two pages and swap back and forth.  That way one is the ‘current’ scene and one is ready to load.  

I’m assuming this means you have many many pages and don’t know in advance what that number will be.

Thanks, nearly got this working.

In the meantime, there’s no need to bounce between two separate pages. Composer can create multiple scenes in one file.

local composer = require "composer" local scene1 = composer.newScene( "scene1" ) local scene2 = composer.newScene( "scene2" ) function scene1:create( event ) --do stuff end scene1:addEventListener( "create", scene1 ) function scene2:create( event ) -- do stuff end scene2:addEventListener( "create", scene2 ) composer.gotoScene( "scene1" )

This thread expands on this idea of creating Composer scenes programmatically:

https://forums.coronalabs.com/topic/47096-creating-composer-scenes-programmatically/

Hi.  Pretty much all the code I’ve written for the Corona Geek hangouts is here:

http://github.com/roaminggamer/CoronaGeek

The composer stuff is here:

Hey Ed, many thanks for the links, good stuff.

The question I have pertains to a comment you made on Corona Geek where you had seen a “really cool example the other day where someone made not a custom transition… but they could substitute their own function as a transition…”

This is something we’ve thought of doing, so for instance, if a scene transition is fading out, have a runtime listener on the sceneGroup’s alpha and then trigger another function to coincide with that…

Anyway, if you can remember where you saw this example, it would be most useful to understand how someone has done this.

Here is a URL of the episode at the time in question:

https://youtu.be/Ht8iSJ8uBms?t=1430

Thanks.

I’m afraid I don’t remember an exact thread link from over 7 months ago.  :blink:   
 
I did however include links to sources in the code:

If I understand what you’re trying to do, you should be able:

  1. Write your own easing.
  2. Insert it into the easing library. (similar to how I added custom transitions to composer, but for easing.* instead)
  3. Use it in a custom scene transition. (again the samples provided show how to code your own, insert, and use it)

That’s about all I can say.  Sorry, but my memory just isn’t that good.

PS - This is what I mean by #1 and #2 above (assume the following is in file customeasing.lua)

local function linear(t, b, c, d) return c \* t / d + b end easing.myLinear = linear

Once you require “customeasing”, the easing library should now have a new easing called ‘myLinear’. (Totally untested but I think this is right.)

Yet more (possibly useful) links:

Oh, and you can change easing linkages at any time.  i.e. If you needed to, you could replace easing.myLinear right before using it.

Finally, there are two more options:

  • enterFrame listener (I think you meant this, not Runtime) - Watching a value and acting when that value reaches a trigger point).
  • Advanced lua coding, wherein you modify the __index metamethod, etc. functions of the scene. (I’m sure there was a blog post here about that, so you might want to page through them to find it (only 158 pages of blog posts :slight_smile:http://coronalabs.com/blog/page/158/))

Thanks again Ed. Yes, it was your last number 2 point that I was looking for a working example - “Watching a value and acting when that value reaches a trigger point”. An enterFrame listener it is. Though we are using a one page, dynamically generated version of Composer which does add a level of difficulty reaching the scene.view… Anyway, will post the results if they add anything to the Composer effectsLIst conversation.

If you’re trying to generate the content in the scene, but want the scene to do transitions, you might use two pages and swap back and forth.  That way one is the ‘current’ scene and one is ready to load.  

I’m assuming this means you have many many pages and don’t know in advance what that number will be.

Thanks, nearly got this working.

In the meantime, there’s no need to bounce between two separate pages. Composer can create multiple scenes in one file.

local composer = require "composer" local scene1 = composer.newScene( "scene1" ) local scene2 = composer.newScene( "scene2" ) function scene1:create( event ) --do stuff end scene1:addEventListener( "create", scene1 ) function scene2:create( event ) -- do stuff end scene2:addEventListener( "create", scene2 ) composer.gotoScene( "scene1" )

This thread expands on this idea of creating Composer scenes programmatically:

https://forums.coronalabs.com/topic/47096-creating-composer-scenes-programmatically/