I am making a program that pick, drag, and drop the ball. In real life, once you pick the ball and drop it, whenever the available object is (what you see is what you get) will only be picked and dropped again and again. However, in the game program, there is something that at first you did pick and drop the ball. When you did the second time, something hit like some sort of an "invisible object" and the physics frame (in pink) is replicating while the frame in green is the wall and the floor. Take a look at these pictures.

Before picking up and drop a ball for the first time... enter image description here

When the ball in dropping... (Showing in pink frame for physics frame) enter image description here

When picking up the second time, the previous pink physics frame did not come off and ended hitting something invisible. enter image description here

So tell me, did I made something wrong in this touchDown() code or not? I have observed something here after I run in debug mode.

public boolean touchDragged(int screenX, int screenY, int pointer) 
    // TODO touchDragged

    float change_x = (Gdx.input.getX()/(cv.getPhysicsCamera().viewportWidth))*5000;
    float change_y = (Gdx.input.getY()/(cv.getPhysicsCamera().viewportHeight))*15;

    x = ((change_x/cv.getPhysicsCamera().viewportWidth)/2) - (rc.getSoccerBallWidth()/2);
    y = (((cv.getPhysicsCamera().viewportHeight) - (change_y/2)) - (rc.getSoccerBallWidth()/2));

    Vector3 touch_point = new Vector3(change_x, change_y, 0);

    // Set new body frame.
    ballDef.type = BodyType.DynamicBody;
    ballDef.position.set(x, y);

    ballBody = wc.getWorld().createBody(ballDef);
    ballBody.setActive(false); // --> Allows you to display a cursor for dragging without letting your soccer ball to fall off while holding.

    return true;

1 Answer 1


Ideally, you'd assign your ball a physics body and update that instead of creating a new physics body every time the user picks up the ball.

E.g. call wc.getWorld().createBody(ballDef); only once when you init the game and only move it to the position of the ball.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .