This seems to work for me. Here are the changes I made to the code you provided:
- Added the posiciones table deceleration, i assume this is somewhere in the code you didn’t post.
- Uncommented the code in the moved section since that is the code that actually moves the box.
- removed the removeBody() thing since that was from my stupid suggestion earlier.
[lua]posiciones = {x=0, y=0}
function onTouch( event )
t = event.target
local estabien = false
local phase = event.phase
if “began” == phase then
display.getCurrentStage():setFocus( t )
–I also tried:
–display.getCurrentStage():setFocus( t, event.id )
t.isFocus = true
– Store initial position
posiciones.x = t.x
posiciones.y = t.y
t.x0 = event.x - t.x
t.y0 = event.y - t.y
elseif t.isFocus then
if “moved” == phase then
t.x = event.x - t.x0
t.y = event.y - t.y0
else
if “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
–this is something “mine”, i think you can forget it
if ( ( event.x < ( posiciones.x - 30 ) ) or ( event.x > ( posiciones.x + 30 ) ) ) or ( ( event.y < ( posiciones.y - 30 ) ) or ( event.y
> ( posiciones.y + 30 ) ) ) then
print(“ESTA BIEN”)
estabien = true
transition.to ( t, { time=450, x=-80, y=t.y } )
else
print(“ES POCO”)
restar_puntos(1)
estabien = false
–t.x = posiciones.x
–t.y = posiciones.y
end
print(“suelto”)
end
end
end
return true
end
local myObject = display.newRect( 0, 0, 100, 100 )
myObject:setFillColor( 255 )
myObject:addEventListener( “touch”, onTouch ) [/lua] [import]uid: 147305 topic_id: 30534 reply_id: 122461[/import]