Reloading A Level Via An Intermediary 'storyboard' Scene.

Hi Everyone… I know this issue has come up on more than a few occasions, but I guess the solution is deifferent for everyone. I had placed it the ‘storyboard’ sub-section of this forum, but as it doesn’t seem to get many views, my faith wavoured slightly… I need a quickish resolution, so please forgive me (moderators and / or people suscribed to the Storyboard API section) for reposting here.

I’m making a casual game (more of an exercise than anything else).I’m using a catapult-style launcher (poached directly from Ghosts Vs Monsters)… here is an example of the ‘touch mechanism’ (it will make sense why I’ve included this later):

local onScreenTouch = function( event ) &nbsp;&nbsp; &nbsp;if event.phase == "began"&nbsp; == false and event.xStart \> 220 and event.xStart \< 420 and event.yStart \> 700 and event.yStart \< 900&nbsp; then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; shotOrb.x = aimball.x; shotOrb.y = aimball.y shotOrb.xScale = 2; shotOrb.yScale = 2 shotArrow.isVisible = true timerText.isVisible = true if shotOrb.isVisible == true then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local xOffset = aimObject.x &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local yOffset = aimObject.y &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local distanceBetween = mCeil(mSqrt( ((event.y - yOffset) ^ 2) + ((event.x - xOffset) ^ 2) )) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;shotOrb.xScale = -distanceBetween \* 0.02 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;shotOrb.yScale = -distanceBetween \* 0.02 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local angleBetween = mCeil(mAtan2( (event.y - yOffset), (event.x - xOffset) ) \* 180 / mPi) + 90 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;aimObject.rotation = angleBetween + 180 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;shotArrow.rotation = aimObject.rotation &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if event.phase == "ended" then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;shotOrb.isVisible = false &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;shotArrow.isVisible = false &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local x = event.x &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local y = event.y &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local xForce = (-1 \* (x - mainObject.x)) \* 1.15&nbsp;&nbsp; &nbsp;--\> 2.75 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local yForce = (-1 \* (y - mainObject.y)) \* 1.15&nbsp;&nbsp; &nbsp;--\> 2.75 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;mainObject:applyForce( xForce, yForce, mainObject.x, mainObject.y ) &nbsp;

Simple enough… Now, I have a reload, or more accurately, a replay-the-level button. - After searching for various ways to achieve this, I went with ‘put an intermediary scene between the original scene and it’s reloaded version’… I’ve taken good care to destroy any listeners that may cause future conflicts, and my intermediary scene looks like this:

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() function scene:createScene( event ) &nbsp;&nbsp; &nbsp;local group = self.view end function scene:enterScene( event ) &nbsp;&nbsp; &nbsp;local group = self.view &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;storyboard.removeScene( "level1" ) &nbsp;&nbsp; &nbsp;storyboard.reloadScene( "level1" ) &nbsp;&nbsp; &nbsp;storyboard.gotoScene("level1") end function scene:exitScene( event ) &nbsp;&nbsp; &nbsp;local group = self.view end function scene:destroyScene( event ) &nbsp;&nbsp; &nbsp;local group = self.view end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene &nbsp;

OK, this isn’t perfect, but it successfully reloads the scene… However, my ‘touch event’ becomes unresponsive because corona can no longer index the x and y co-ordinates specified in my ‘catapult launcher’.

Really can’t get my head around this one. If anyone can tell me where I’ve gone wrong or perhaps suggest a better way to reload a scene from scratch I’d be eternally grateful.

Thanks

Mark

Can you post the code for the scene where you add the touch listener for the catapult?

Hey Rob, thanks for the comeback.

The events and ascociated functions are in my first snippet. The launcher/touch mechanism is initiated with a listener:

Runtime:addEventListener( "touch", onScreenTouch ) &nbsp;

Thanks again

Also, it might be worth mentioning… I’m currently working from a hotel room on a Windows based laptop… The windows ‘terminal’ doesn’t report any error, I just lose the touch mechanism, but when I’m in the studio, working on a mac, my Corona terminal reports ‘failed to index x/y co-ords’ or something along those lines… It concerns the x/y co-ordinates that are referenced within the touch event.

Can you post the code for the scene where you add the touch listener for the catapult?

Hey Rob, thanks for the comeback.

The events and ascociated functions are in my first snippet. The launcher/touch mechanism is initiated with a listener:

Runtime:addEventListener( "touch", onScreenTouch ) &nbsp;

Thanks again

Also, it might be worth mentioning… I’m currently working from a hotel room on a Windows based laptop… The windows ‘terminal’ doesn’t report any error, I just lose the touch mechanism, but when I’m in the studio, working on a mac, my Corona terminal reports ‘failed to index x/y co-ords’ or something along those lines… It concerns the x/y co-ordinates that are referenced within the touch event.

I am having a very similar problem with reloading the scene to this one.  Was wondering if there was any final resolution?

-Bill

I guess I didn’t ask the question well enough.  You posted only the Runtime:addEventListener.  I was hoping to see where you were executing that line relative to your storyboard module.

Also I’m a big confused by why you’re doing:

  if event.phase == “began” == false

That seems kind of odd.

I am having a very similar problem with reloading the scene to this one.  Was wondering if there was any final resolution?

-Bill

I guess I didn’t ask the question well enough.  You posted only the Runtime:addEventListener.  I was hoping to see where you were executing that line relative to your storyboard module.

Also I’m a big confused by why you’re doing:

  if event.phase == “began” == false

That seems kind of odd.