Swipe code works in Corona simulator but not in Xcode simulator or on device

I’ve got the following code in main.lua and using storyboard.
I’m trying to create swipes which will change between scenes. It works in the Corona simulator but not in the Xcode simulator or on an iOS device. Not sure how to trouble shoot that.

Any help would be appreciated. If you need more info, let me know.

I’m using the latest build as of April 11, 2012 (783)

Here is my current main.lua file.

  
-----------------------------------------------------------------------------------------  
--  
-- main.lua  
--  
-----------------------------------------------------------------------------------------  
  
local storyboard = require "storyboard"  
display.setStatusBar( display.HiddenStatusBar ) -- hide the status bar  
-- Global Variables  
\_W = display.contentWidth;  
\_H = display.contentHeight;  
  
oldCurrentChapter = currentChapter  
currentChapter = 0  
nextChapter = 0  
previousChapter = 0  
  
currentSlide = 0  
nextSlide = 0  
previousSlide = 0  
  
-- load menu.lua  
storyboard.gotoScene( "c0s0" )  
  
-- Add any objects that should appear on all scenes below (e.g. tab bar, hud, etc.):  
  
-- Universal Swipe functions  
  
local beginX  
local beginY   
local endX   
local endY   
   
local xDistance   
local yDistance   
function fileExists(fileName, base)  
 local path = system.pathForFile( fileName, system.ResourceDirectory )  
  
 if (path)then  
 local fhd = io.open( path )  
 print (path)  
 if fhd then  
 return true  
 end  
  
 end  
  
  
end  
   
function checkSwipeDirection()  
   
 xDistance = math.abs(endX - beginX)   
 yDistance = math.abs(endY - beginY)  
  
 if xDistance \> 50 or yDistance \> 50 then   
 if xDistance \> yDistance then  
 if beginX \> endX then  
 print("swipe left")  
 --Go to next scene  
 if fileExists(nextChapter .. ".lua") then  
 storyboard.gotoScene( nextChapter, "slideLeft", 800 )  
 end  
 else   
 print("swipe right")  
 --Go to previous scene  
 if fileExists(previousChapter .. ".lua") and (currentChapter ~= 0) then  
 storyboard.gotoScene( previousChapter, "slideRight", 800 )  
 end  
 end  
 else   
 if beginY \> endY then  
 print("swipe up")  
  
 --Move the scene up  
 if fileExists(nextSlide .. ".lua") then  
 storyboard.gotoScene( nextSlide, "slideUp", 800 )  
  
 end  
 else   
 print("swipe down")  
  
 --Move the scene down  
 if fileExists(previousSlide .. ".lua") then  
 storyboard.gotoScene( previousSlide, "slideDown", 800 )  
  
 end  
  
 end  
 end  
  
 else  
  
 --This was considered a touch event  
 --Run touch events here.  
  
 print ("This was a touch not a swipe")  
 end   
end  
   
   
function swipe(event)  
 if event.phase == "began" then  
 beginX = event.x  
 beginY = event.y  
 end  
  
 if event.phase == "ended" then  
 endX = event.x  
 endY = event.y  
 checkSwipeDirection();  
 end  
  
end  
   
Runtime:addEventListener("touch", swipe)  

And here is the first scene (base on scenetemplate.lua from storyboard) if you want to test it. If you want to add additional scenes, basically duplicate this file and change the “currentChapter” and “currentSlide” variables at the top. Name the files eg. c0s0.lua, c1s0.lua, c1s1.lua

  
----------------------------------------------------------------------------------  
--  
-- c0s0.lua  
-- Chapter 0 Slide 0  
--  
----------------------------------------------------------------------------------  
  
local storyboard = require( "storyboard" )  
local scene = storyboard.newScene()  
  
----------------------------------------------------------------------------------  
--   
-- NOTE:  
--   
-- Code outside of listener functions (below) will only be executed once,  
-- unless storyboard.removeScene() is called.  
--   
---------------------------------------------------------------------------------  
  
---------------------------------------------------------------------------------  
-- BEGINNING OF YOUR IMPLEMENTATION  
---------------------------------------------------------------------------------  
  
-- Called when the scene's view does not exist:  
function scene:createScene( event )  
 local group = self.view  
  
 -----------------------------------------------------------------------------  
  
 -- CREATE display objects and add them to 'group' here.  
 -- Example use-case: Restore 'group' from previously saved state.  
  
 -----------------------------------------------------------------------------  
 oldCurrentChapter = currentChapter  
 currentChapter = 0  
 nextChapter = "c" .. (currentChapter + 1) .. "s0";  
 previousChapter = "c" .. (currentChapter - 1) .. "s0";  
  
 oldCurrentSlide = currentSlide  
 currentSlide = 0  
 nextSlide = "c" .. currentChapter.."s" .. (currentSlide + 1);  
 previousSlide = "c" .. currentChapter.."s" .. (currentSlide - 1);  
  
  
-- Create the slides for this chapter  
-- Slide 0  
 local slide0 = display.newGroup();  
  
 local startBtn = display.newText( "Start", 0, 0, native.systemFont, 24 )  
 startBtn.x = \_W/2;  
 startBtn.y = \_H/2;  
 startBtn:setTextColor ( 255, 255, 255 );  
  
 local startSquare = display.newRect(0,0,180, 50);  
 startSquare.x = \_W - \_W/2;  
 startSquare.y = \_H - \_H/7;  
 startSquare:setFillColor(gradient);  
 slide0:insert(startSquare);  
 slide0:insert(startBtn);  
-- Insert slides into parent group  
  
 group:insert(slide0)  
  
end  
-- Called immediately after scene has moved onscreen:  
function scene:enterScene( event )  
 local group = self.view  
  
 -----------------------------------------------------------------------------  
  
 -- INSERT code here (e.g. start timers, load audio, start listeners, etc.)  
  
 -----------------------------------------------------------------------------  
  
if oldCurrentChapter~=0 then  
 storyboard.removeScene( "c" .. oldCurrentChapter .. "s" .. oldCurrentSlide );  
end  
  
  
end  
-- Called when scene is about to move offscreen:  
function scene:exitScene( event )  
 local group = self.view  
  
 -----------------------------------------------------------------------------  
  
 -- INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.)  
  
 -----------------------------------------------------------------------------  
  
end  
-- Called prior to the removal of scene's "view" (display group)  
function scene:destroyScene( event )  
 local group = self.view  
  
 -----------------------------------------------------------------------------  
  
 -- INSERT code here (e.g. remove listeners, widgets, save state, etc.)  
  
 -----------------------------------------------------------------------------  
  
end  
---------------------------------------------------------------------------------  
-- END OF YOUR IMPLEMENTATION  
---------------------------------------------------------------------------------  
  
-- "createScene" event is dispatched if scene's view does not exist  
scene:addEventListener( "createScene", scene )  
  
-- "enterScene" event is dispatched whenever scene transition has finished  
scene:addEventListener( "enterScene", scene )  
  
-- "exitScene" event is dispatched before next scene's transition begins  
scene:addEventListener( "exitScene", scene )  
  
-- "destroyScene" event is dispatched before view is unloaded, which can be  
-- automatically unloaded in low memory situations, or explicitly via a call to  
-- storyboard.purgeScene() or storyboard.removeScene().  
scene:addEventListener( "destroyScene", scene )  
  
---------------------------------------------------------------------------------  
  
return scene  

[import]uid: 111212 topic_id: 24772 reply_id: 324772[/import]