Snap to new position on drag and drop

I am writing a simple drag and drop game and have no issues with the drag and drop. There is also no issue with grabbing the start location since it is event.target in the listener. However I cannot identify the end point of the drag action, i.e. drop point.

I have two arrays, one for the image to be moved and one for the underlying player board. Both arrays contain their respective identifiers (position in the array) and the corresponding x and y.

How can I get the target position (x,y). It will always be the cell next to the origin as you can only move one cell at a time in either direction. Up, down, right, left or diagonally from the starting point moving one cell.

Sorry, code looks like it did not format correctly.

--------------------------------------------------------------- -- dragDrop() -- listener to control the drag and drop functionality --------------------------------------------------------------- -- outOf Bounds: flag to show the player has moved past the&nbsp; --&nbsp; &nbsp; &nbsp; &nbsp;board boundries, snaps image back to origin. -- cellNum: position of player board array matched to event.target -- zX, zY: moving x,y for drag -- minX, maxX, minY, maxY: boundry limits from playing piece build -- gridButtons: array form playing board --------------------------------------------------------------- function dragDrop( self,event ) &nbsp; &nbsp; &nbsp; &nbsp; outOfBounds = false &nbsp; &nbsp; &nbsp; &nbsp; cellNum = event.target.id if event.phase == "began" then &nbsp; &nbsp; display.getCurrentStage():setFocus( event.target ) --- -- store starting x,y --- &nbsp; &nbsp; self.markX = self.x &nbsp; &nbsp; self.markY = self.y elseif event.phase == "moved" then --- -- determine moved location --- &nbsp; &nbsp; print("id's: ", global.gridButtons[cellNum].num, global.gridButtons[cellNum].x,global.gridButtons[cellNum].y,event.target.id) &nbsp; &nbsp; local x = (event.x - event.xStart) + self.markX &nbsp; &nbsp; local y = (event.y - event.yStart) + self.markY &nbsp; &nbsp; zX = x &nbsp; &nbsp; zY = y elseif event.phase == "ended"&nbsp; or event.phase == "cancelled" then &nbsp; &nbsp; display.getCurrentStage():setFocus(nil) &nbsp; &nbsp; print("ended x, y: ",zX, zY, " markX, markY: ",math.floor(self.markX,1),math.floor(self.markY,1)) --- -- max/minX and max/minY are from the 1st and last listener cells -- &nbsp; &nbsp; if ((zX \< minX) or (zX \> maxX)) then --- -- out of X bounds, snap to origin --- &nbsp; &nbsp; &nbsp; outOfBounds = true &nbsp; &nbsp; &nbsp; --print("out of bound: ") &nbsp; &nbsp; &nbsp; x = self.markX &nbsp; &nbsp; &nbsp; y = self.markY &nbsp; &nbsp; elseif ((zY \< minY) or (zY \> maxY)) then --- -- out of Y bounds, snap to origin --- &nbsp; &nbsp; &nbsp; outOfBounds = true &nbsp; &nbsp; &nbsp; --print("out of bound: ") &nbsp; &nbsp; &nbsp; x = self.markX &nbsp; &nbsp; &nbsp; y = self.markY &nbsp; &nbsp; end --- -- validate bounds check for boundry snap to cell -- lock x/y for target cell for snap to cell --- &nbsp; &nbsp; print("bounds check val: ", outOfBounds,math.floor(zX,1), math.floor(zY,1) ) &nbsp; &nbsp; if (not outOfBounds) then &nbsp; &nbsp; &nbsp; self.x, self.y = zX, zY &nbsp; &nbsp; end&nbsp; &nbsp;&nbsp; elseif event.phase == "moved" then end return true end