Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Fade in objects one by one
Started by Wing Sep 21 2018 10:57 PM

4 replies to this topic
fade in on complete
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Wing

[GLOBAL: userInfoPane.html]
Wing
  • Observer

  • 2 posts
  • Corona SDK

local function textFadeIn(group,i)
    if group[i] ~= nil then
        transition.fadeIn( group[i], { time = 1000, onComplete = textFadeIn(group,i+1)} )
    end
end

textFadeIn(textGroup,1)

Hi all, I am new to Corona SDK. I want to fade in all text object in a display group one by one. The group[i+1] should start the transition after the group[i] complete the transition. However, in the above code, all the object will transition at the same time.

 

Is there any problem in the code? Thanks.



[TOPIC: post.html]
#2

cyberparkstudios

[GLOBAL: userInfoPane.html]
cyberparkstudios
  • Contributor

  • 538 posts
  • Corona SDK

Wing,

 

add a delay field to the fadeIn function .....  multiply the delay time by i, then each item will fade in 

local function textFadeIn(group, i)
    if group[i] ~= nil then    	
        transition.fadeIn( group[i], {delay = i * 4000, time = 1000, onComplete = textFadeIn(group, i+1)} )
    end
end

 as in nearly all cases, there are multiple ways to do things..  this way works, but there are likely more efficient wats to do the same thing.

 

If you want the first image to start fade in immediately, just change the delay argument to this  :  delay = (i-1) * 4000

 

Best of luck in your coding.

 

Bob



[TOPIC: post.html]
#3

CoronaChris

[GLOBAL: userInfoPane.html]
CoronaChris
  • Contributor

  • 161 posts
  • Corona SDK

The problem here is the listener you specify for onComplete.

 

If you write

onComplete = function() textFadeIn(group,i+1) end

instead of

onComplete = textFadeIn(group,i+1)

it works. Rob posted a very good explanation here:

https://forums.coronalabs.com/index.php?app=forums&module=forums&section=findpost&pid=389155

 

Hope that helps :)



[TOPIC: post.html]
#4

cyberparkstudios

[GLOBAL: userInfoPane.html]
cyberparkstudios
  • Contributor

  • 538 posts
  • Corona SDK

Wing, 

 

Chris is correct here.  An anonymous function is probably the best way to do what you are wanting to do there.  Mine was just a quick 'hack' fix, which works, but it's bad because it ignores the issue that Chris was smart enough to point out. 

 

It is best to do it the right way.  But more importantly, it would be most helpful if you do  take the time to read Rob's explanation link Chris provided.  Rob is excellent at explaining these type things.  Once you get a grasp of how it works and why; it will help save you a lot of headaches later on. 

 

 

Good luck!

Bob



[TOPIC: post.html]
#5

Wing

[GLOBAL: userInfoPane.html]
Wing
  • Observer

  • 2 posts
  • Corona SDK

Chris & Bob,

 

It works. Thanks for answering. I love you all so much.

 

Wing




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: fade in, on complete