0

我编写了一个使用 jbox2D 显示圆圈体的代码。但是当运行这段代码时,我得到了空白屏幕。现在如何在屏幕上显示这个刚体。我需要使用任何视图在屏幕上显示它吗?请帮助..

import org.jbox2d.collision.shapes.CircleShape;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.BodyType;
import org.jbox2d.dynamics.FixtureDef;
import org.jbox2d.dynamics.World;

import android.app.Activity;
import android.os.Bundle;

public class FirstBox2DGameActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//       setContentView(R.layout.main);     
        Vec2 gravity = new Vec2(0.0f, -10.0f);
        boolean doSleep = true;
        World world = new World(gravity, doSleep);

        // Body definition is created as below.
        BodyDef bd = new BodyDef();
        bd.position.set(100, 200);
        bd.type = BodyType.STATIC;

        // body Shape
        CircleShape cs = new CircleShape();
        cs.m_radius = 5.0f;

        // Fixture defines the material properties of the body. Fixtures are
        // also used for attaching shape to the body. These material properties
        // describe how two bodies should react when they collide with each
        // other.
        FixtureDef fd = new FixtureDef();
        fd.shape = cs;
        fd.density = 0.5f;
        fd.friction = 0.3f;
        fd.restitution = 0.5f;

        // Now final step is to create a body and add fixture to it. The bodies
        // are created using World class.
        Body body = world.createBody(bd);
        body.createFixture(fd);
    }
}
4

1 回答 1

0

好吧,您也必须在屏幕上绘制它。:) 在这里查看示例http://disanji.net/2010/12/18/android-2d-box2d/

于 2012-05-06T09:22:55.753 回答