The 'legendary' Reload Scene Problem... Struggling.

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’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;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;

Simple enough… Now, I have a reload, or more accurately, a replay-the-level button. - After seacrhing 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

Please carry on any replies to this in the other thread:

http://forums.coronalabs.com/topic/33795-reloading-a-level-via-an-intermediary-storyboard-scene/

Locking.

Please carry on any replies to this in the other thread:

http://forums.coronalabs.com/topic/33795-reloading-a-level-via-an-intermediary-storyboard-scene/

Locking.