Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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).

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

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

share|improve this answer
    
It is. However, if gravity applied, it might jump instead. –  David Dimalanta Mar 14 '13 at 1:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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