@jayantv
yup exactly that’s the reason why i am using target.isFocus but just forgot to take that in moved and ended phase
updated code :–
[lua]module(…, package.seeall)
function new()
local localGroup = display.newGroup()
local rect = display.newRect(0,0,50,50)
local function moveRect(event)
local target = event.target
local phase = event.phase
if “began” == phase then
display.getCurrentStage():setFocus( target )
target.isFocus = true
– Store initial position
target.x0 = event.x - target.x
target.y0 = event.y - target.y
elseif “moved” == phase and target.isFocus == true then
if event.y + target.height * 0.5 < display.contentHeight * 0.5 then
target.y = event.y - target.y0
end
target.x = event.x - target.x0
elseif “ended” == phase and target.isFocus == true then
display.getCurrentStage():setFocus( nil )
target.isFocus = false
end
end
rect:addEventListener(“touch”,moveRect)
return localGroup
end[/lua]
thanks [import]uid: 12482 topic_id: 9363 reply_id: 35659[/import]