Collision is resolved

I want to insert a picture into the SlidingMenu, but an error occurs:
ERROR: Cannot translate an object before collision is resolved.
How I can remove collision?

I just want to move the picture to the SlidingMenu and from the SlidingMenu to another place

In the function “collision_heroes” I did comments, what I use but it doesn’t work

	local function collision_heroes (self, event)
		local phase = event.phase;
		local _id = event.target.id
		local id = event.other.id
		
		if (phase == "began") then
			print( event.other.id );
			print( id );
			
			if ( _id == "hero" and id == "drop") then
				print("good")

				--event.target:removeSelf()
				--event.target.collision = nill
				--physics.pause()
				--physics.removeBody(event.target)
				--Runtime:removeEventListener("collision", event.target)
				--event.target:removeEventListener("collision", collision_heroes)
				event.target.x = 50
				event.target.y = 50
				scrollView:insert( event.target )
				--physics.start()
			else
				print("bad")
			end
		end
		return true
	end
	
	local function showSlidingMenu( event )
		if ( "ended" == event.phase ) then
	 
			scrollView = widget.newScrollView
			{
				width = 460,
				height = 100,
				scrollWidth = 1200,
				scrollHeight = 100,
				verticalScrollDisabled = true
			}
			scrollView.x = display.contentCenterX
			scrollView.y = display.contentCenterY
			local scrollViewBackground = display.newRect( 600, 50, 1200, 100 )
			scrollViewBackground:setFillColor( 0, 0, 0.2 )
			scrollView:insert( scrollViewBackground )
		end
		return true
	end
	
	for i,t in pairs(decoded) do
		t.name = display.newImage(sceneGroup, "img/local/heroes/"..t.name.."/"..t.name..".png", _W/math.random(1,8), _H/math.random(1,8));
		--scrollView:insert( t.name )
		t.name:scale( champ_view+minScale, champ_view+maxScale );
		t.name.id = t.id;
		t.name.collision = collision_heroes;
		t.name:addEventListener( "collision" );
		t.name:addEventListener( "touch", drag_champ );
	end

I think you need to add a delay around the code you want to execute on collision, because you are not allowed to change objects that are currently involved in a collision being resolved, just like the error message says.

So in your collision handler, try to add something like:

timer.performWithDelay(10, function()
  -- Modify your colliding objects here
end)
1 Like