using the 'gameUI' with params, and making object drag easier

Greetings,

I’m using the ‘gameUI.lua’ to help me drag an object- code found here:

https://code.google.com/p/corona-sdk-samples/source/browse/trunk/Samples/GettingStarted/rope/gameUI.lua


I have it implemented and works.  Two questions - if I want to edit the params ( maxForce, frequency, dampingRatio ) of the dragBody - How would I do this (probably really simple…)?  I’m using the example to trigger the dragBody on object found below:

local dragBody = gameUI.dragBody object:addEventListener( "touch", dragBody )

ALSO - my object that I’m using to drag is relatively small.  So it’s a little difficult to register a touch on the object.  What would be the best method to make the drag registration of the object easier (say 4x the size of the actual object) while still keeping the object/physics body same size… ?

Thanks!

Seth

Hi Seth,

The sample you found is extremely old and, while it may work, I honestly can’t recommend that you use it.

It appears that you’re looking to move a physical body/object using a “rope” joint. A better and more modern sample for you to follow is located in your local Corona application folder:

CoronaSDK-XXXX > SampleCode > Physics > Joints

There, look for the “rope.lua” file and see how different properties can be applied to make the rope behave differently.

As for making the object itself easier to touch (larger) while keeping the same physical size, you can adjust the size of the internal physics body, making it smaller than the boundaries of the image itself. If it’s a radial object, simply reduce the radius of the physics body. If it’s a polygonal object, you can create a custom polygonal shape for the body. If you’re not familiar with different methods of constructing physics bodies, I can point you in the right direction (just let me know).

Hope this helps,

Brent

Hey @Brent Sorrentino,

Thanks for the info.

I’ll take a look at the sample project when I get back on my project computer tonight.

But basically I’m just looking for a way to drag a single object and being able to ‘toss’ with some momemtum from drag.  Not using a rope or anything at the moment.  I managed to accomplish something like this myself but ‘gameUI’ seemed to accomplish it abeit smoother (I used the physics property ‘isFixedRotation’ on my object too).

So I understand what you are saying about re-configuring the size of the physics object vs actual object.  Problem is I want the physics of the object to correspond with the image size… while still having a large area in which to ‘touch’ the object.  I was thinking about a sensor attached to object via joints, but I don’t believe you can use a sensor in such a way.

I’m still in the design phases so I’m not entirely sure if I’ll be using the drag and toss idea.  I may just have user click on object, then do a swipe-based method to determine how to launch the object (speed/angle of swipe)… something I have coded in LUA before.

Appreciate the help!

Hi @henson802,

Sure, using a rope joint to touch/drag a physical object is just one option, not the only option. :slight_smile:

Typically, if you want a larger area to “drag” an object while keeping its physical body size smaller, you can just pad the image with transparent pixels around it, then customize the physics body to be smaller, as needed. This will allow the object to still register touch/tap events, but its physical behavior will coincide with the body size you’ve defined.

Brent

Ahh makes sense, for whatever reason I was thinking the touch/tap needed to be on the physics object to register and not just on a display object.

Thanks Brent, your input helps as usual

There are also numerous sample’s in our sample apps that show you how to drag objects around.

Rob

I had a ‘drag’ function that was derived from a couple Sample Apps.

My original concern was passing params to the ‘gameUI.lua’… I’m a little new when it comes to passing params to/from functions.  I was using that because I was using chunks of the liquid fun stuff for my next project… and one of the examples used the gameUI.lua , which I’ve learned is a little outdated - I’ll just go back to more recent sample Apps that show drag/toss objects and incorporate that into it if I decide to go with that design scheme.

Thanks again to both you, Rob and Brent - always helpful.  Live and learn :slight_smile:

Hi Seth,

The sample you found is extremely old and, while it may work, I honestly can’t recommend that you use it.

It appears that you’re looking to move a physical body/object using a “rope” joint. A better and more modern sample for you to follow is located in your local Corona application folder:

CoronaSDK-XXXX > SampleCode > Physics > Joints

There, look for the “rope.lua” file and see how different properties can be applied to make the rope behave differently.

As for making the object itself easier to touch (larger) while keeping the same physical size, you can adjust the size of the internal physics body, making it smaller than the boundaries of the image itself. If it’s a radial object, simply reduce the radius of the physics body. If it’s a polygonal object, you can create a custom polygonal shape for the body. If you’re not familiar with different methods of constructing physics bodies, I can point you in the right direction (just let me know).

Hope this helps,

Brent

Hey @Brent Sorrentino,

Thanks for the info.

I’ll take a look at the sample project when I get back on my project computer tonight.

But basically I’m just looking for a way to drag a single object and being able to ‘toss’ with some momemtum from drag.  Not using a rope or anything at the moment.  I managed to accomplish something like this myself but ‘gameUI’ seemed to accomplish it abeit smoother (I used the physics property ‘isFixedRotation’ on my object too).

So I understand what you are saying about re-configuring the size of the physics object vs actual object.  Problem is I want the physics of the object to correspond with the image size… while still having a large area in which to ‘touch’ the object.  I was thinking about a sensor attached to object via joints, but I don’t believe you can use a sensor in such a way.

I’m still in the design phases so I’m not entirely sure if I’ll be using the drag and toss idea.  I may just have user click on object, then do a swipe-based method to determine how to launch the object (speed/angle of swipe)… something I have coded in LUA before.

Appreciate the help!

Hi @henson802,

Sure, using a rope joint to touch/drag a physical object is just one option, not the only option. :slight_smile:

Typically, if you want a larger area to “drag” an object while keeping its physical body size smaller, you can just pad the image with transparent pixels around it, then customize the physics body to be smaller, as needed. This will allow the object to still register touch/tap events, but its physical behavior will coincide with the body size you’ve defined.

Brent

Ahh makes sense, for whatever reason I was thinking the touch/tap needed to be on the physics object to register and not just on a display object.

Thanks Brent, your input helps as usual

There are also numerous sample’s in our sample apps that show you how to drag objects around.

Rob

I had a ‘drag’ function that was derived from a couple Sample Apps.

My original concern was passing params to the ‘gameUI.lua’… I’m a little new when it comes to passing params to/from functions.  I was using that because I was using chunks of the liquid fun stuff for my next project… and one of the examples used the gameUI.lua , which I’ve learned is a little outdated - I’ll just go back to more recent sample Apps that show drag/toss objects and incorporate that into it if I decide to go with that design scheme.

Thanks again to both you, Rob and Brent - always helpful.  Live and learn :slight_smile: