Error while doing animation in Corona SDK

I created an animation with images transition with Corona SDK version 2018.3280, it works fine when the application starts, but when I open a new scene and return to the scene where the animation is, it goes crazy.

Video: https://www.youtube.com/watch?v=1U8rtMsGGEY

 

home.lua

local img local img2 img = display.newImageRect(sceneGroup,"images/2016.jpg",display.contentWidth, imgX) img.anchorX = 0 img.anchorY = 0 img.y = navBar.y + navBar.height img2 = display.newImageRect(sceneGroup,"images/2016-2.jpg",display.contentWidth, imgX) img2.anchorX = 0 img2.anchorY = 0 img2.y = navBar.y + navBar.height img2.x = img.x + img.width function scene:show( event ) local sceneGroup = self.view local phase = event.phase time = timer.performWithDelay(2000, anim1) function anim1() trans1 = transition.to(img,{time= 1500,x = -display.contentWidth}) trans2 = transition.to(img2,{time= 1500,x = 0}) time1 = timer.performWithDelay(2000,anim2) end function anim2() time2 = timer.performWithDelay(2000,anim3) img.x = display.contentWidth end function anim3() trans3 = transition.to(img2,{time= 1500,x = -display.contentWidth}) trans4 = transition.to(img,{time= 1500,x = 0,onComplete = anim4}) end function anim4() img2.x = display.contentWidth time3 = timer.performWithDelay(2000,anim1) end if ( phase == "will" ) then elseif ( phase == "did" ) then end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then elseif ( phase == "did" ) then timer.cancel(time) --timer.cancel(time1) --timer.cancel(time2) --timer.cancel(time3) transition.cancel(trans1) transition.cancel(trans2) transition.cancel(trans3) transition.cancel(trans4) composer.removeHidden() end end 

How can I solve this?

Please make a TINY demo app that demonstrates this issue so we can see all of what you’re doing.  That code alone is not likely the whole issue.

Tip: When I read the title I thought this would be about sprites (animations). 

For your info (to avoid future confusion), transition.* may be used to move, modify, etc objects, but it isn’t generally referred to as animation. 

We simply call them transitions. 

You can attach zip files to posts, by zipping up the project, then clicking the ‘more reply options’ button below.  That will then pull up this interface:

attaching_files.jpg

My code is simple, link for download here…

https://www.sendspace.com/file/93v6tr

Hi.  Thanks  Please attach it as I showed.  I don’t trust 3rd party download sites.

Sorry.

It’s cool. I just like to be careful. Looking now.

Hi again. This is NOT a mini example. It looks like your full game/app… I don’t have the time or desire to dig through a full project to find the problem code.

Also, it is a good debug step to reproduce issues in a mini testbench. This is often how I find the source of my problem.

Can you just make an example that demonstrates the single issue you’re posting about?

If it helps you can use this starter:
https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/askEdStarter.zip

To be absolutely clear, all you should really need is:

  • build.settings - basic setup
  • config.lua - basic setup
  • main.lua - all your demo code goes in here
  • images - if needed
  • sprite definition lua file(s) - if needed

You know what.  I may be wrong here.  Your interaction may be related to the way you’re using composer.* so strike that last post.

I will take a look.   Just a bit thanks.

I’m sorry again, I hope this simple example can be analyzed and given a solution.

sorry my English.

OK.  I’ve looked  AT THE ORIGINAL POSTED CODE  and I can see that you have some bad behavior, but I don’t know where it is coming from.

Things I noticed:

  • code needs some general cleaning and indenting.  i’d suggest 3 spaces instead of 2.  I’m mentioning this because it is hard to read and thus is hard to debug.
  • You seem to be destroying home when you leave.  If you’re going to do this and if your transition time is 0, there is no reason to use the show() method.
  • You start timers TWICE in show.  i.e. They are NOT in  in a will or did phase check.
  • ‘time’ is a global.  it should be a file-level local declared at the top

Sorry, I could’t figure it out.  This is why I ask for super simple tiny demos.  There is just too much code to penetrate.

My best guess is that you’re staring the timer multiple times and not properly canceling them since you only have the handle to the last timer you started.

Ok, I’ll see if I can debug these timers.

Hi again.

I looked at your newer code.  I cleaned it up a bit and modified it.

Compare what I’m doing to your code.

That Cool! Thanks a lot, although the code changed seems a little complicated (I am a beginner) I was happy that my problem was solved even with a little more code.

I’ll take a look at the modifications to see if I learn!

Thank you very much

Yeah…sorry about that.

I made those changes because your original method had a number of best-practices issues that would have caused no end of problems:

  • globals all over the place (and quite possibly having the same names used in other scenes?)
  • destroying scenes on hide —> did phase (some say “Yes, it is OK.”, Is say “No, it is not.”)
  • ignoring will/did phases in show when setting up timers

  Also, you were using timers and transitions in a sub-optimal way. 

My unified single transition + onComplete listener approach is shorter and safer.  That said, it is more technical, so I understand if it seems confusing at first.

Please make a TINY demo app that demonstrates this issue so we can see all of what you’re doing.  That code alone is not likely the whole issue.

Tip: When I read the title I thought this would be about sprites (animations). 

For your info (to avoid future confusion), transition.* may be used to move, modify, etc objects, but it isn’t generally referred to as animation. 

We simply call them transitions. 

You can attach zip files to posts, by zipping up the project, then clicking the ‘more reply options’ button below.  That will then pull up this interface:

attaching_files.jpg

My code is simple, link for download here…

https://www.sendspace.com/file/93v6tr

Hi.  Thanks  Please attach it as I showed.  I don’t trust 3rd party download sites.

Sorry.

It’s cool. I just like to be careful. Looking now.

Hi again. This is NOT a mini example. It looks like your full game/app… I don’t have the time or desire to dig through a full project to find the problem code.

Also, it is a good debug step to reproduce issues in a mini testbench. This is often how I find the source of my problem.

Can you just make an example that demonstrates the single issue you’re posting about?

If it helps you can use this starter:
https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/askEdStarter.zip

To be absolutely clear, all you should really need is:

  • build.settings - basic setup
  • config.lua - basic setup
  • main.lua - all your demo code goes in here
  • images - if needed
  • sprite definition lua file(s) - if needed