I need the following logic.
1. box2d object is flying top of the screen.
2. If make long mouse click, the flying object come down and hit ground.
3. If release the mouse click, then the object move to top.
I did first point using
body_->SetGravityScale(0);
body_->SetLinearVelocity(velocity);
How will i move top to bottom and again bottom to top?
Thanks in advance.
I'm am going to assume that you actually have something on the ground (like a ground plane) for the body to hit.
First, to detect the long mouse click, and assuming you are using cocos2d-x, you are going to need a way to detect the long mouse click.
For that, you will either need to key off the touch events in your scene or create a class that handles long touches. For that, here are a couple of options:
From what you want, I would favor the second, since it gives a call when the finger goes down and then comes up.
For the rest of it, you can set the velocity based on the mouse events. Or apply forces to the bodies to make them move.