How to launch objects that you drag around?

Hi Coronaville,

I know how to drag objects around by assigning a callback function to them, what I’m interested to do is how to launch those objects.

What I mean by “launch” is when you drag an object around, if you leave your finger, it would continuously move on the direction that you were dragging it.

How I can achieve this?

Thanks. [import]uid: 206803 topic_id: 34415 reply_id: 334415[/import]

If you’re using physics, you could applyForce or applyLinearImpluse to the object on the ended phase of the touch event.

If you’re not using physics and you want it to move, you could use some simple triangle math to compute a future X, Y position and use a transition.to to move it in the ended phase of the touch event. [import]uid: 199310 topic_id: 34415 reply_id: 136793[/import]

I achieved this with using gameUI but I prefer a lighter solution like the one you mentioned.

  1. So I have to decrease end point of drag from the start position of drag and give that vector to applyForce or applyLinearForce, right?

  2. I checked gameUI’s dragBody method and it just do this:
    stage:setFocus( body, nil )
    body.isFocus = false

how this results on object continuing where it was dragging to?

  1. Is using gameUI heavy for this purpose?

* May the Force be with you. [import]uid: 206803 topic_id: 34415 reply_id: 136802[/import]

Hi Aidin,
I might suggest another option if you’re using physics, and that’s the touch joint. What I like about the touch joint is that it gives you a theoretical physical point that the attached physics body follows, with variable damping and frequency to control how closely it follows the touch point.

Where this might help you even further is that when the player releases the drag, you wouldn’t need to figure out the trajectory/speed to calculate some ongoing force. The body will already have physical forces applied to it from the drag, so releasing it will simply “snap the joint” and the body will go about its physical motion.

Up to you, of course, but this is another method to explore.

Brent [import]uid: 200026 topic_id: 34415 reply_id: 136859[/import]

Thanks Brent.

That’s the way gameUI works, right? Please correct me if I’m wrong.

  1. I watched the video tutorial for “DragMe” but it didn’t give much info regarding how it works, but just showed to use it with your game. Where can I read about gameUI more in detail?

  2. How heavy is using joints, performance-wise? I’ll have 8-10 of them present at the same time and I want to support as more devices as I can.

Thanks. [import]uid: 206803 topic_id: 34415 reply_id: 136875[/import]

Hi Aidin,
Is “gameUI” a Corona module or a Codeshare module? I can take a look at how it’s doing the “drag” thing, if you like.

In regards to 8-10 items being dragged, do you want to have all of them “drag-n-launch” enabled at once? Or, do you intend to just have 8-10 of them on the screen, and the player can move them about (and launch them) individually? If the latter, performance shouldn’t be a problem with joints… you would actually be creating/removing a touch joint each time, as that joint doesn’t really endure… and so effectively, if you’re manipulating one object at a time, you only have one touch joint at a time.

Brent
[import]uid: 200026 topic_id: 34415 reply_id: 136901[/import]

If you’re using the UI module included in some of the Corona Sample Code, with the dragBody function, then no, it won’t be too taxing for the device. At least it shouldn’t be. I’ve tried quite a number of joints at once, and no problems with memory usage come up for me.

If you’re using something else, I’m not sure. [import]uid: 147322 topic_id: 34415 reply_id: 136940[/import]

Hi Brent,

gameUI is from here: Corona SDK\Sample Code\Physics\DebugDraw\gameUI.lua [import]uid: 206803 topic_id: 34415 reply_id: 136971[/import]

@Caleb,

Thanks for the reply. [import]uid: 206803 topic_id: 34415 reply_id: 136972[/import]

If you’re using physics, you could applyForce or applyLinearImpluse to the object on the ended phase of the touch event.

If you’re not using physics and you want it to move, you could use some simple triangle math to compute a future X, Y position and use a transition.to to move it in the ended phase of the touch event. [import]uid: 199310 topic_id: 34415 reply_id: 136793[/import]

I achieved this with using gameUI but I prefer a lighter solution like the one you mentioned.

  1. So I have to decrease end point of drag from the start position of drag and give that vector to applyForce or applyLinearForce, right?

  2. I checked gameUI’s dragBody method and it just do this:
    stage:setFocus( body, nil )
    body.isFocus = false

how this results on object continuing where it was dragging to?

  1. Is using gameUI heavy for this purpose?

* May the Force be with you. [import]uid: 206803 topic_id: 34415 reply_id: 136802[/import]

Hi Aidin,
I might suggest another option if you’re using physics, and that’s the touch joint. What I like about the touch joint is that it gives you a theoretical physical point that the attached physics body follows, with variable damping and frequency to control how closely it follows the touch point.

Where this might help you even further is that when the player releases the drag, you wouldn’t need to figure out the trajectory/speed to calculate some ongoing force. The body will already have physical forces applied to it from the drag, so releasing it will simply “snap the joint” and the body will go about its physical motion.

Up to you, of course, but this is another method to explore.

Brent [import]uid: 200026 topic_id: 34415 reply_id: 136859[/import]

Thanks Brent.

That’s the way gameUI works, right? Please correct me if I’m wrong.

  1. I watched the video tutorial for “DragMe” but it didn’t give much info regarding how it works, but just showed to use it with your game. Where can I read about gameUI more in detail?

  2. How heavy is using joints, performance-wise? I’ll have 8-10 of them present at the same time and I want to support as more devices as I can.

Thanks. [import]uid: 206803 topic_id: 34415 reply_id: 136875[/import]

Hi Aidin,
Is “gameUI” a Corona module or a Codeshare module? I can take a look at how it’s doing the “drag” thing, if you like.

In regards to 8-10 items being dragged, do you want to have all of them “drag-n-launch” enabled at once? Or, do you intend to just have 8-10 of them on the screen, and the player can move them about (and launch them) individually? If the latter, performance shouldn’t be a problem with joints… you would actually be creating/removing a touch joint each time, as that joint doesn’t really endure… and so effectively, if you’re manipulating one object at a time, you only have one touch joint at a time.

Brent
[import]uid: 200026 topic_id: 34415 reply_id: 136901[/import]

If you’re using the UI module included in some of the Corona Sample Code, with the dragBody function, then no, it won’t be too taxing for the device. At least it shouldn’t be. I’ve tried quite a number of joints at once, and no problems with memory usage come up for me.

If you’re using something else, I’m not sure. [import]uid: 147322 topic_id: 34415 reply_id: 136940[/import]

Hi Brent,

gameUI is from here: Corona SDK\Sample Code\Physics\DebugDraw\gameUI.lua [import]uid: 206803 topic_id: 34415 reply_id: 136971[/import]

@Caleb,

Thanks for the reply. [import]uid: 206803 topic_id: 34415 reply_id: 136972[/import]