How To Make Gameui.dragbody Work With Resized Physic?

Hi, I’m resizing physic size of my display objects but when I drag it around with gameUI.dragBody to drag around it, it uses the display object itself not the resized physic! In other words, I’m increasing size of the physic object to make it easier to drag but drag only works with the image, not the resized physic. Thanks.

Any ideas? Is my question not clear?

I define my object with this:

local purpleFoodCollisionFilter = { categoryBits = 2, maskBits = 1 } -- collides with (1) only local purpleFoodPhysicSettings = { density=0.2, friction=0, bounce=0.95, radius=35.0, filter=purpleFoodCollisionFilter } foodObject = display.newImageRect("food\_purple.png", 35, 47) foodObject.myType = "Purple" foodObject.collision = onPurpleFoodCollision foodObject:setFillColor( leftMonsterColorsData[currentLevel].r,  leftMonsterColorsData[currentLevel].g, leftMonsterColorsData[currentLevel].b ) foodObject:addEventListener("collision", foodObject); -- TODO: Why we pass the same object as last parameter. physics.addBody( foodObject, "dynamic", purpleFoodPhysicSettings) currentSceneGroup:insert(foodObject) // Registering for touch event    foodObject:setReferencePoint(display.CenterReferencePoint);    --we need to revert reference point to center physic will move it by center. foodObject:addEventListener("touch", localDrag);

and localDrag is just a wrapper for gameUI.dragBody:

local function localDrag( event ) -- isTouched is a flag to indicate that player previously touched this food object and if later on this -- object hits with a monster, then that collision is valid. So this prevents foods to get eaten by -- monsters when they move freely and accidentally collide with a monster. -- (We can toggle this to false after some time, if we want) -- event.target.isTouched = true; local dragget\_target = event.target; dragget\_target.isTouched = true; -- foodObject:addEventListener("touch", foodOnTouch); -- foodTouchHandler(event) -- gameUI.dragBody( event, {} ) -- gameUI.dragBody(event, {maxForce = 100, frequency = 2} ) -- slow, elastic dragging -- gameUI.dragBody(event, {maxForce = 100, frequency = 2, center = true } ) -- slow, elastic dragging return gameUI.dragBody(event, {maxForce = 20000, frequency = 10, dampingRatio = 0.9, center = true }) --very tight -- return true -- The magic-- line end

Interestingly, if I turn on debug mode, I can see physic object that is larger than the display image and when they collide, Corona uses this bigger and resized physic body but when I want to drag the foodobject around, it only accepts touch for where the actual image is, not the increased physic around it.

I think gameUI.dragBody is getting the display object, rather then physic object. I have to solve this somehow.

And ideas?

So if I want to break down my question again even simpler: Is there anyway for gameUI.dragbody to drag the physic attached to an object rather than display image itself?

Hi Aidin,

I sort of addressed this in the other post where you asked… not in specific to gameUI, but just in general. Would that solution work for this perhaps?

Brent

Any ideas? Is my question not clear?

I define my object with this:

local purpleFoodCollisionFilter = { categoryBits = 2, maskBits = 1 } -- collides with (1) only local purpleFoodPhysicSettings = { density=0.2, friction=0, bounce=0.95, radius=35.0, filter=purpleFoodCollisionFilter } foodObject = display.newImageRect("food\_purple.png", 35, 47) foodObject.myType = "Purple" foodObject.collision = onPurpleFoodCollision foodObject:setFillColor( leftMonsterColorsData[currentLevel].r,  leftMonsterColorsData[currentLevel].g, leftMonsterColorsData[currentLevel].b ) foodObject:addEventListener("collision", foodObject); -- TODO: Why we pass the same object as last parameter. physics.addBody( foodObject, "dynamic", purpleFoodPhysicSettings) currentSceneGroup:insert(foodObject) // Registering for touch event    foodObject:setReferencePoint(display.CenterReferencePoint);    --we need to revert reference point to center physic will move it by center. foodObject:addEventListener("touch", localDrag);

and localDrag is just a wrapper for gameUI.dragBody:

local function localDrag( event ) -- isTouched is a flag to indicate that player previously touched this food object and if later on this -- object hits with a monster, then that collision is valid. So this prevents foods to get eaten by -- monsters when they move freely and accidentally collide with a monster. -- (We can toggle this to false after some time, if we want) -- event.target.isTouched = true; local dragget\_target = event.target; dragget\_target.isTouched = true; -- foodObject:addEventListener("touch", foodOnTouch); -- foodTouchHandler(event) -- gameUI.dragBody( event, {} ) -- gameUI.dragBody(event, {maxForce = 100, frequency = 2} ) -- slow, elastic dragging -- gameUI.dragBody(event, {maxForce = 100, frequency = 2, center = true } ) -- slow, elastic dragging return gameUI.dragBody(event, {maxForce = 20000, frequency = 10, dampingRatio = 0.9, center = true }) --very tight -- return true -- The magic-- line end

Interestingly, if I turn on debug mode, I can see physic object that is larger than the display image and when they collide, Corona uses this bigger and resized physic body but when I want to drag the foodobject around, it only accepts touch for where the actual image is, not the increased physic around it.

I think gameUI.dragBody is getting the display object, rather then physic object. I have to solve this somehow.

And ideas?

So if I want to break down my question again even simpler: Is there anyway for gameUI.dragbody to drag the physic attached to an object rather than display image itself?

Hi Aidin,

I sort of addressed this in the other post where you asked… not in specific to gameUI, but just in general. Would that solution work for this perhaps?

Brent

Thanks Brent. I understood your reply but I cannot get it applied to my problem.

I haven’t read the other post, but if the drag is being done based on a touch event, physics really isn’t involved is it?  The solution to this if I want a bigger touch area is to pad transparent pixels around the image.   Again I have no experience with that gameui, just pondering.

Wow, does transparent parts of an image get touch events?! That’s awesome if possible!

Thanks Rob, I’ll try it and report back.

May the [Corona] force be with you!

Thanks Brent. I understood your reply but I cannot get it applied to my problem.

I haven’t read the other post, but if the drag is being done based on a touch event, physics really isn’t involved is it?  The solution to this if I want a bigger touch area is to pad transparent pixels around the image.   Again I have no experience with that gameui, just pondering.

Wow, does transparent parts of an image get touch events?! That’s awesome if possible!

Thanks Rob, I’ll try it and report back.

May the [Corona] force be with you!