I just tried it, using your code, and it seemed to work fine for me… When I touch a piece, it doesn’t even jump a pixel, and drags around pretty well. Drop it anywhere, it drops properly (doesn’t jump). Pick it back up from there, and it doesn’t jump a pixel, moves nicely.
[code]
–***********************************************************************************************–
–***********************************************************************************************–
local screenGroup = display.newGroup()
local halfW = display.contentCenterX
local halfH = display.contentCenterY
local puzzleLeft =300 ; puzzleTop=300
local bgRect;
local isSelected = false; – Global and object levels to prevent multiple object collisions
local tapXOffset = 0
local tapYOffset = 0
local function main()
local i
local puzzleGroup = display.newGroup()
local puzzleFile=“pic.png”;
local pzObject = {} --Holds each puzzle piece
local pzMask = {}
local puzzleWidth=500; puzzleHeight=500;
bgRect = display.newRect( puzzleGroup, 0, 0, display.contentWidth, display.contentHeight )
bgRect:setFillColor( 0, 0, 0, 255 )
bgRect.alpha = 0
bgRect.isVisible = false
for i=1,4,1 do
pzObject[i] = display.newImageRect( puzzleFile, puzzleWidth, puzzleHeight )
pzObject[i].id=i; pzObject[i].isSelected=false;
puzzleGroup:insert( pzObject[i] )
pzObject[i].x = puzzleLeft; pzObject[i].y = puzzleTop;
– SET MASK
local maskFile = “masks/mask” … i … “.png”
pzMask[i] = graphics.newMask( maskFile )
pzObject[i]:setMask( pzMask[i] )
pzObject[i].isHitTestMasked = true --prevent transparent pixel touch
pzObject[i]:setReferencePoint( display.CenterReferencePoint )
–***********************************************************************************************
– TOUCH / MOVE
–***********************************************************************************************
local touchPz = function( event )
– Tip: For all but the simplest cases, it is best to extract the values you need from ‘event’ into local variables.
local phase = event.phase
local target = event.target
local x = event.x
local y = event.y
print(“phase–>” …phase)
print(“target.id–>” …target.id)
if not isSelected and event.phase == “began” then
target.isSelected = true; isSelected = true;
target:toFront()
tapXOffset = x - target.x
tapYOffset = y - target.y
print(" – x,y offset == ", tapXOffset, tapYOffset)
elseif(event.phase == “moved” and target.isSelected == true) then
target.x = x - tapXOffset; target.y = y - tapYOffset
elseif event.phase == “ended” then
target.isSelected = false; isSelected = false;
end
end
pzObject[i]:addEventListener( “touch”, touchPz )
end
end
main()
[/code] [import]uid: 79933 topic_id: 35345 reply_id: 140495[/import]