Hi All,
I promise, this is the last post on this puzzle I am building.
So I scrapped the physics route and I am working on a logic/math approach for managing the sliding of the key, past bricks and out of the game.
My objective is to prevent the key from being dragged too far upwards, so I essentially want to stop the drag event.
When the key reaches the edge of the grid, regardless if player is still dragging (touching).
I want something else to prevent the dragging motion.
My only semi-workable solution is to currently remove the Event Listener.
But this is permanent, and then stops me from re-adding it as Lua is linear code and not OO, so reads down the code, and invokes/actions on the way back up.
So I’ve no way to recall back down the code.
There are no pause/re-start abilities with event listeners.
So now I am stuck.
Is there a way to then re-invoke the event listener?
or am I still using the wrong approach.
Is there a way to force the event.phase to cancel other then with the release of the mouse/finger touch being listed off of the device? But if there is a way I can not find it.
local function dragKey(event) itemKey = event.target local phase = event.phase if ( "began" == phase ) then display.currentStage:setFocus( itemKey ) itemKey.touchOffsetY = event.y - itemKey.y elseif ( "moved" == phase ) then itemKey.y = event.y - itemKey.touchOffsetY itemKey.topEdge = itemKey.y - itemKey.height/2 if (itemKey.topEdge \<= bounds.yMin ) then print("key reached top edge of grid") itemKey:removeEventListener( "touch", dragKey ) elseif (itemKey.topEdge \>= bounds.yMax ) then puzzleCompleted() end elseif ( "ended" == phase or "cancelled" == phase ) then display.currentStage:setFocus( nil ) end -- itemKey:addEventListener( "touch", dragKey ) return true -- Prevents touch propagation to underlying objects end
Again thanks in advance.
Angela