Composer Overlay transitions not cancelling as expected

Hi All, 

Any help would be most appreciated.

My issue is that when i cancel a transition of the overlay, prior to returningto existing scene, all of a sudden the overlay “teleports” to the transtion endpoint before going to the next scene. It doesnt cancel that transitoin as expected, nor handle the overlay.hideOverlay transition. 

It seems a bit buggy, but i am not sure if i am incorrectly handling the transition. I have read on other posts that there can be some wierd behavior with transitions.  Code is posted below for the overlay. This is test code, as i am using images instead of rects in my actual code, and extra buttons, but just a green rectangle button for my example. The ‘jump’ is still there. 

Can anyone provide any advice how to cancel the transitions correctly in overlay, such that they leave the overlay in its current position and not have it jump, before disappearing. The reason i want to get this right is to give my game nice tweens for overlays, e.g. for new levels, hints etc

or is this a bug? Letme know if you need more coden for other test scenes

thanks

Nick

simulator


format: ipad landscape

corona build: Version 2014.2189 (2014.3.6)

I am calling this overlay as follows

[lua]

local overlayOptions = {

    isModal = true,

    effect = “fade”,

    time = 400

    }

}

local function btnTap ( event )

    if event.phase == “ended” then

       composer.showOverlay( “overlayPause”, overlayOptions )

    end

    return true

end

[/lua]

Heres the overlay code:overlayPause.lua

[lua]

local composer = require( “composer” )

local scene = composer.newScene()


– “scene:create()”

function scene:create( event )

   local sceneGroup = self.view

   function sceneGroup:getButtonRect(x,y,w,h)

      local rect = display.newRect(x,y,w,h)

      – rect:setReferencePoint(display.TopLeftReferencePoint)

      self:insert(rect)

      function rect:touch(event)

         sceneGroup:onButtonTouch(event)

         return true

      end

      rect:addEventListener(“touch”, rect)

      return rect

   end

   function sceneGroup:onButtonTouch(event)

      local phase = event.phase

      local target = event.target

      if phase == “began” then

         if target == self.playBtn then

             composer.hideOverlay(“fade”, 800)

         end

         return true

      end

   end

   function sceneGroup:cancelTween(tween)

      if tween ~= nil then

         transition.cancel(tween)

         tween = nil

      end

   end

   

   – Initialize the scene here.

   – Example: add display objects to “sceneGroup”, add touch listeners, etc.

   – local folder = “ComposerTest/images/”

   – local overlay = display.newImage (folder … “overlayv2.png”, 900 , 500)

   local overlay = display.newRect(1000, 500, 900 , 300) 

            overlay.x = 500

            overlay.y = 600

            sceneGroup:insert (overlay)

   – local playBtn   = sceneGroup:getButton( folder …  “playBtn.png”)

   local playBtn   = sceneGroup:getButtonRect( 0, 0, 100 , 100)

   playBtn:setFillColor(0.3,0.5,0.3)

   sceneGroup.playBtn  = playBtn

   playBtn.x = overlay.x - overlay.width / 3

   playBtn.y = overlay.y + overlay.height/4

   

   sceneGroup.originY = sceneGroup.y

   sceneGroup.y = -300

   sceneGroup.x = 2000

   – sceneGroup.y = G.cH + 100

end

– “scene:show()”

function scene:show( event )

   local sceneGroup = self.view

   local phase = event.phase

   if ( phase == “will” ) then

      – Called when the scene is still off screen (but is about to come on screen).

      sceneGroup.tweenEnter = transition.to( sceneGroup, { time=12000, y=0

                                                          ,onComplete = function() sceneGroup:cancelTween(sceneGroup.tweenEnter) end

                                                         })

   elseif ( phase == “did” ) then

      – Called when the scene is now on screen. – Insert code here to make the scene come alive.  – Example: start timers, begin animation, play audio, etc.

   end

end

– “scene:hide()”

function scene:hide( event )

   local sceneGroup = self.view

   local phase = event.phase

   if ( phase == “will” ) then

      – Called when the scene is on screen (but is about to go off screen). – Insert code here to “pause” the scene. – Example: stop timers, stop animation, stop audio, etc.

      

      sceneGroup:cancelTween(sceneGroup.tweenEnter) – doesnt stop but keeps sliding

   elseif ( phase == “did” ) then

      – Called immediately after scene goes off screen.

   end

end

– “scene:destroy()”

function scene:destroy( event )

   local sceneGroup = self.view

   – Called prior to the removal of scene’s view (“sceneGroup”). – Insert code here to clean up the scene. – Example: remove display objects, save state, etc.

end


– Listener setup

scene:addEventListener( “create”, scene )

scene:addEventListener( “show”, scene )

scene:addEventListener( “hide”, scene )

scene:addEventListener( “destroy”, scene )


return scene

[/lua]

When you cancel a transition, it will just stop at that point. It will not finish, nor return back.

In my case, when i am changing scene and a transition needs to be ‘nicely removed’, I will just change the alpha of the objects so it isn’t so obvious.

Another options is to cancel the transition and have a function to complete it straightaway).

Hi Yosu, thanks for the comment. 

I agree, the cancel should just stop the transition at the point the button that calls cancel is clicked. But I am seeing a very different result when its clicked during transition (initiating a cancel) vs when the transition is complete. 

This makes me think that either the way i am cancelling it is wrong, OR that theres some buggy issue as to how transitions are cancelled, and how the touch handler, or isModal = true is working during transition  Can you see any obvious errors in my code.

I have used closures to deal with transition cleanup onComplete (may not be nescessary) but I cant understand why the jup to the transition end occurs, nor why the button press seems to tunnel when in transition and not when the transition is complete. 

Does anyone else have any thoughts?

All replies much appreciated

When you cancel a transition, it will just stop at that point. It will not finish, nor return back.

In my case, when i am changing scene and a transition needs to be ‘nicely removed’, I will just change the alpha of the objects so it isn’t so obvious.

Another options is to cancel the transition and have a function to complete it straightaway).

Hi Yosu, thanks for the comment. 

I agree, the cancel should just stop the transition at the point the button that calls cancel is clicked. But I am seeing a very different result when its clicked during transition (initiating a cancel) vs when the transition is complete. 

This makes me think that either the way i am cancelling it is wrong, OR that theres some buggy issue as to how transitions are cancelled, and how the touch handler, or isModal = true is working during transition  Can you see any obvious errors in my code.

I have used closures to deal with transition cleanup onComplete (may not be nescessary) but I cant understand why the jup to the transition end occurs, nor why the button press seems to tunnel when in transition and not when the transition is complete. 

Does anyone else have any thoughts?

All replies much appreciated