here is my code .
--------------------------------------------------------------------------------- -- -- scene.lua -- --------------------------------------------------------------------------------- local sceneName = ... local composer = require( "composer" ) local json = require( "json" ) local loadsave = require( "loadsave" ) local myData = require( "mydata" ) local physics = require("physics") -- Load scene with same root filename as this file local scene = composer.newScene( sceneName ) --------------------------------------------------------------------------------- centerX = display.contentCenterX centerY = display.contentCenterY screenLeft = display.screenOriginX screenWidth = display.contentWidth - screenLeft \* 2 screenRight = screenLeft + screenWidth screenTop = display.screenOriginY screenHeight = display.contentHeight - screenTop \* 2 screenBottom = screenTop + screenHeight display.contentWidth = screenWidth display.contentHeight = screenHeight function scene:create( event ) local sceneGroup = self.view -- Called when the scene's view does not exist -- -- INSERT code here to initialize the scene -- e.g. add display objects to 'sceneGroup', add touch listeners, etc myData.settings = loadsave.loadTable( "settings.json" ) local pl2 = self:getObjectByName( "pl2" ) local bk = self:getObjectByName( "bk" ) BaseT = self:getObjectByName( "BaseT" ) local borderDown = self:getObjectByName( "borderDown" ) local borderUp = self:getObjectByName( "borderUp" ) local borderLeft= self:getObjectByName( "borderLeft" ) local borderRight = self:getObjectByName( "borderRight" ) borderDown.name="borderDown" borderUp.name="borderUp" borderLeft.name="borderLeft" borderRight.name="borderRight" borderDown.name="borderDown" pl2.name="pl2" BaseT.name="BaseT" --physics.setDrawMode( "hybrid" ) --physics.setDrawMode( "debug" ) local CoronaDev = display.newText( "Level 2",25,25, "Exo-ExtraLight.otf", 13 ) CoronaDev.x=30 CoronaDev.y=-20 sceneGroup:insert(CoronaDev) CoronaDev:setTextColor( 0.5,0.5,0.5 ) ---New Move With Tweaks --- local function handleSwipe( event ) if ( event.phase == "began" ) then -- display.getCurrentStage():setFocus( event.target ) -- This made object stop moving once the swipe stop in fast way elseif ( event.phase == "moved" ) then local dX = event.x - event.xStart local dY = event.y - event.yStart if event.phase == "moved" then if dX \>= 10 then event.target:setLinearVelocity(600,0) elseif dX \<= -10 then event.target:setLinearVelocity(-600,0) elseif dY \>= 10 then event.target:setLinearVelocity(0,600) elseif dY \<= -10 then event.target:applyLinearImpulse(0,-600) end end return true elseif ( event.phase == "ended" or event.phase == "cancelled" ) then --event.target:setLinearVelocity(0,0) --- This put strange stop if the touch was so short end end local SaveLevel = function () myData.settings.currentLevel = 2 end SaveLevel() local GoToNextLevel = function ( event ) if ( event.phase == "began" ) then if event.target.name == "BaseT" then Level=2 composer.showOverlay( "pass") pl2:setLinearVelocity(0,0) myData.settings.unlockedLevels = 3 end end end local SquareGoAway = function ( event ) if ( event.phase == "began" ) then if event.target.name == "borderDown" or event.target.name == "borderUp" or event.target.name == "borderLeft" or event.target.name == "borderRight" or event.target.name == "borderRightDown"then local GameOver=1 composer.gotoScene ("GameOver") return true end end end local SoundImpact = function ( event ) if ( event.phase == "began" ) then SoundImpactName = audio.play (SoundImpact,{ channel=3}) pl2:setLinearVelocity(0,0) return true elseif ( event.phase == "ended" ) then end return true end borderRight:addEventListener( "collision", SquareGoAway ) borderUp:addEventListener( "collision", SquareGoAway ) borderLeft:addEventListener( "collision", SquareGoAway ) borderDown:addEventListener( "collision", SquareGoAway ) BaseT:addEventListener( "collision", GoToNextLevel ) pl2:addEventListener( "touch", handleSwipe ) pl2:addEventListener( "collision", SoundImpact ) Runtime:addEventListener( "enterFrame", SaveLevel ) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase loadsave.saveTable( myData.settings, "settings.json" ) end function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's "view" (sceneGroup) -- -- INSERT code here to cleanup the scene -- e.g. remove display objects, remove touch listeners, save state, etc --BaseT:removeEventListener( "collision", GoToNextLevel ) end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene
i removed the ( dX >= -2 and dX <= 2 ) and stuff becuase it made the swipe hard to complete .
pl2 is the square ( dynamic , Fixed Rotation , Active , Awake , Sleeping Allowed , 0 Angular Damping and 0 linear Damping , 0 bounce , 100 Friction , 20 Density , 0 Radius )
Other objects ( other Squares ) ( Static , Active , Friction 100 , bounce 0 , linear and angular damping are 0 , Radius 0 , Density is 100 )
No X and Y Gravity .
I am using Composer GUI
Corona SDK 2912 . and test same behavior on Smart Phone
it is a maze and if i cant fix this strange behavior players can use it to be moved to the exit ( hole ) of the maze without having to solve the maze using Vertical and Horizontal movement