Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9216747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:28:59+00:00 2026-06-18T02:28:59+00:00

I am a newbie learner to JBox2D. I was just trying JBox2D for the

  • 0

I am a newbie learner to JBox2D. I was just trying JBox2D for the first time on Android(I know Android development and I’m good in it) because my project needed physics.

Now, the tutorials and “Official User Manual” of Box2D said that negative gravity would result in objects being attracted downwards. But, in my case the object is being attracted upwards when I set Vec2‘s second parameter to be negative! Weird.

Here’s the code which results in a circle shape going up on its own:

The Gravity:

Vec2 gravity = new Vec2(0.0f, -50.0f);
boolean doSleep = true;
world = new World(gravity, doSleep);

The circle shape is being made by following code:

    //body definition
    BodyDef bd = new BodyDef();
    bd.position.set(200, 500);  
    bd.type = BodyType.DYNAMIC;

    //define shape of the body.
    CircleShape cs = new CircleShape();
    cs.m_radius = 10f;  

    //define fixture of the body.
    FixtureDef fd = new FixtureDef();
    fd.shape = cs;
    fd.density = 1f;
    fd.friction = 0.2f;        
    fd.restitution = 0.8f;

    //create the body and add fixture to it
    body =  world.createBody(bd);
    body.createFixture(fd);

And I’m using SurfaceView canvas to draw:

canvas.drawCircle(body.getPosition().x, body.getPosition().y, 10, paint);

And stepp-ing as follows:

float timeStep = 1.0f / 60.f;
int velocityIterations = 6;
int positionIterations = 2;

world.step(timeStep, velocityIterations, positionIterations);

So, what’s wrong within my code? I am unable to identify the mistake I’ve done.

Also,
I’m making a tennis-like 2D game on Android for which I’ll be using JBox2D. So, can anybody tell me a tutorial/book on JBox2D? Though I googled vigorously, I couldn’t find a good tutorial on it. (Though Box2D seems to be much popular instead of JBox2D)

I would be extremely grateful if someone could help me out here. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:29:00+00:00Added an answer on June 18, 2026 at 2:29 am

    In Box2D there is standard coordinate system: Y directed up, X to the right. In the graphic systems, usual, coordinate system has Y directed down, because window has static top-left corner. Looks like at your graphic system all the same. So, what in Box2D is moving down, you see as moving up.

    It is the irritable problem, and directing gravity up is not the best solution. If you change only gravity, then you will need think about up-down problem in many other cases, for example, when define bodies, apply forces and so on. The most irritable, that it is not easy to understand, how physic coordinates conform graphic (for example, in one of my projects I had to draw points on paper, then turn paper back, rotate on 180 grades and look on the light :).

    You can’t change Box2D coordinate system, but, most likely, you can easy change coordinate system of graphic system by changing translation matrix. For example, in OpenGL it looks like this:

    glScalef(1.0, -1.0, 1.0);
    

    But take attention, after this, all that have positive Y coordinate will be not visible on the screen (it will be above the top edge of the window). So, you will need work with negative coordinates. If you don’t want this, you can translate matrix down like this:

    glTranslatef(0.0, -windowHeight.0, 0.0)
    

    But before, think what to do if window would be resized.

    About second question. I doubt whether you can find anywhere tutorial or book for JBox2D. JBox2D is port of Box2D (that means, it is exact copy of Box2D), and writing special book for it looks strange. Learn Box2D, and you will have no problem with JBox2D. For example, you can look there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a newbie and just learned that if I define say package my.first.group.here;
Newbie question (I'm just getting started with Python and Pydev): I've created a project
I am trying to figure out whether a web development project is feasible at
Newbie question: I just installed VisualSVN Server and created a repository. I noticed that
I'm a total newbie for database-based website. I just learned designing website from zero
I'm a newbie in ASP.NET and am trying to learn a little more. I
newbie question here.. I'm trying to return the LAT LNG values from the array.
again a total newbie question from me about Haskell, and Leskah. (First, a subjective
So I'm stuck on a newbie problem once more :D I'm trying to mash
Hey everybody, I am just newbie at Python. I wanted to write a script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.