1
\$\begingroup\$

Normally, a physics frame in pink (see image below) gives the body for detecting hit signal. It usually either falls down or lifts up depending on the gravity orientation. The question is: Is it possible to move or manipulate sprite through X and Y coordinate without needing to use the gravity code from a physics engine like bodyeditor-loader-sources.jar (e.g. ballBody.setGravityScale(100.1f);) so that I can move simply either by dragging, change the value initially, or moving it by D-pad?

enter image description here

\$\endgroup\$
2
\$\begingroup\$

I used DynamicBody for my missiles, set their gravity scale to 0f, and I could move them freely the way I wanted to.

You might want to refer to Box2d documentation, chapter 7.1. You can set their flag isSensor to true, if you want them to report collisions instead of respond to them according to physics laws.

But from now on, you should use your physical body location as sprite location (remember, that Box2d uses meters as dimension unit, so you need to convert it to units your using internally for your objects; otherwise you will get different result for physics-representation and graphical-representation).

\$\endgroup\$
1
  • \$\begingroup\$ I accept your answer for one reason: you shared me with this manual. Now, I might probably gonna use this as instruction manual. \$\endgroup\$ – David Dimalanta Mar 14 '13 at 1:43
1
\$\begingroup\$

A simple way to move the body on the X, Y axises is using impulses or forces.

You could manipulate the impulses with the gdx input processor.

Example :

  If (Gdx.input.isKeyPressed(Keys.LEFT)) {
            //move the body to the left 
             Body.applyLinearImpulse(new Vector2(-1 , 0), body.getPositon());
}

Note that in the vector I put -1 so the ball will recieve multiple impulses and it's width wil decrease by 1. P.S: If you insert a positive value, the body will move right

\$\endgroup\$
1
  • \$\begingroup\$ It is. However, if gravity applied, it might jump instead. \$\endgroup\$ – David Dimalanta Mar 14 '13 at 1:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.