Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How do I stop all transitions stored in a table?
Started by norman.rozental Mar 01 2019 04:27 AM

- - - - -
4 replies to this topic
transitions table
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

norman.rozental

[GLOBAL: userInfoPane.html]
norman.rozental
  • Enthusiast

  • 86 posts
  • Corona SDK

I have the following code which fades in and out an object using transitions.  After a certain amount of time I'd like to cancel these transitions and remove them from memory.

 

However after calling the clearTransitions() method below I can see that the tables are cleared (size is 0) however the transitions still run.  Why do they still run?  Any info would be greatly appreciated.


arrowFadeInTransitions = {}
arrowFadeOutTransitions = {}
arrows = {rect1, rect2, rect3} -- some display object like a rectangle for example

beginFadingArrows(arrows)

beginFadingArrows = function(arrows)
     for i = 1, #arrows do
        local arrow = arrows[i]
         timer.performWithDelay(400*i,function() fadeInArrow(arrow) end)
     end
end

fadeInArrow = function(self)
    self.onComplete = fadeOutArrow
    if #arrowFadeInTransitions > 7 then  -- clear the transitions and stop them running
        clearTransitions()
    end
    arrowFadeInTransitions[#arrowFadeInTransitions + 1] = transition.to(self,{alpha = 1, time=900, onComplete = self})
end

fadeOutArrow = function(self)
    self.onComplete = fadeInArrow
    arrowFadeOutTransitions[#arrowFadeOutTransitions + 1] = transition.to(self,{alpha = 0, time=900, onComplete = self})
end

clearTransitions = function()
    for i=#arrowFadeInTransitions,1,-1 do
     transition.cancel(arrowFadeInTransitions[i])
     arrowFadeInTransitions[i]=nil
    end

    for i=#arrowFadeOutTransitions,1,-1 do
     transition.cancel(arrowFadeOutTransitions[i])
     arrowFadeOutTransitions[i]=nil
    end

    print(#arrowFadeInTransitions)  -- sizes are 0 but transitions still run
    print(#arrowFadeOutTransitions) -- sizes are 0 but transitions still run
end

 



[TOPIC: post.html]
#2

davebollinger

[GLOBAL: userInfoPane.html]
davebollinger
  • Corona Geek

  • 1,337 posts
  • Enterprise

suggest you assign an ".id" property to each "arrow" and monitor (ie print something) whenever a transition starts or finishes.
 
i think (did not attempt to run the code) you've got some mixed-up logic in there, specifically the "if #arrowFadeInTransitions > 7 then" bit.  (it's so mixed up that i'm not even sure what it's intended to do - so not entirely sure how to suggest fixing it)

 

i think, given the initial delays, and timings of the transitions, that you are NOT guaranteed that the first 7 transitions are on unique objects.  (especially since you seem to only have 3 - it's not clear where that "magic" number 7 is coming from)

 

i think "half" of the transitions you're cancelling are already dead, but you'll end up creating another "half-batch" of transitions on the remaining objects before you reach 7 total transitions and clear them again (and again cancelling half that are already dead).

 

then you fire off a new one, so i don't see a way this system ever ends (just confirming as you've reported) but i can't guess at the desired result to offer a possible "fix" for it.



[TOPIC: post.html]
#3

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,793 posts
  • Enterprise

Transitions support the concept of tags. If you have a group of transitions that you need to pause or cancel at the same time, simply assign them the same tag, then you can cancel or pause by tag.

 

While this won't help with the issues that @davebollinger pointed out, it's a way of assigning an id, using transition parameters and standard features.

 

Rob



[TOPIC: post.html]
#4

norman.rozental

[GLOBAL: userInfoPane.html]
norman.rozental
  • Enthusiast

  • 86 posts
  • Corona SDK

Thanks for the replies.  The magic number 7 is just a test to see if the transitions stop after a short period of time.  Probably not the best idea to show what I was trying to achieve.  What I probably didn't make clear is that I want to clear the transitions from memory as this animation is only done during one scene.  I don't want the transitions continually being added to the table and taking up memory.



[TOPIC: post.html]
#5

norman.rozental

[GLOBAL: userInfoPane.html]
norman.rozental
  • Enthusiast

  • 86 posts
  • Corona SDK

Thanks again for the replies Rob and Dave.  I moved the 'clearTransaction()' outside the create transition method and all transitions are cancelled and cleared as expected.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: transitions, table