Libgdx box2d Practice --- release the ball (2: Introduction to box2d)

Source: Internet
Author: User
Tags libgdx
Zookeeper

Box2d Official Website: http://box2d.org/

Box2d v2.1.0 User Guide Translation: http://blog.csdn.net/complex_ OK /article/category/871440

Libgdx uses JNI to encapsulate the C ++ version of box2d, making it much faster than other physical engines such as jbox2d.



I. Basic

Bodydef

A body definition holds all the data needed to construct a rigid body. You can safely re-use body definitions. shapes are added to a body after construction.

It is responsible for defining all the data required by the body, which can be reused. The shape and body must be bound after it.

I understand that it can be used to define data such as the object model type and put it into the body.

A common usage is to define the type:

For example

Bodydef ballbodydef = new bodydef (); // build object ballbodydef. type = bodytype. dynamicbody; // definition type. dynamicbody is an uncontrolled dynamic object, kinematicbody is a controlled dynamic object, and staticbody is a static object.


Body

A rigid body. These are created via world. createbody.

This is a very hard object. Do not think about changing its shape. We can only create it through the world. createbody method.


The usage is as follows (ballmodels is body ):

ballModels = world.createBody(ballBodyDef);
ballModels.createFixture(fd);

Box2ddebugrenderer

It is used to test the graphical display of box2d. The graphic shape is drawn by different colors.

Chainshape, circleshape, edgeshape, polygonshape 

They all inherit from shap and are the most basic graphics.

Fixture

Binds shapes to objects with certain material properties, such as density. Must be generated by body. createfixture.

Fixturedef 

Fixture attribute declaration, which can be reused.

Fixturedef FD = new fixturedef (); FD. density = 1; // density FD. friction = 0f; // friction FD. restitution = 0.5f; // 0-is a fully elastic collision FD. shape = shape;

World 

The world class manages all physics entities, dynamic simulation, and asynchronous queries. The world also contains efficient memory management facilities.

Manage all physical entities, dynamically simulate, and asynchronously query. It also includes an efficient memory management mechanism.

Physical world, managing all bodies,

For example:

<Span style = "color: #33cc00;"> world = New World (New vector2 (0,-10f), false ); // represents the physical world with a downward acceleration of 10 </span>
<span style="color:#33cc00;"></span>

Because the time in the physical world is different from the time in the render, we usually need to convert the time, that is, add the following in the render method:

World. Step (1/60f, 10, 10 );

At the same time, the reference point of the physical world is in the center of the screen, and the stage is (0, 0). I hope you can pay attention to it.

The length of the physical world is not calculated in pixels. Pay attention to unit conversion. The general conversion ratio is 1: 60, and the physical world is 1.



Libgdx box2d Practice --- release the ball (2: Introduction to box2d)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.