2012-04-25 25 views
0

我使用jbox2D編寫了一個用於顯示圓體的代碼。但是,當運行這個代碼我有空白屏幕。現在如何在屏幕上顯示這個剛體。我需要使用任何視圖來顯示它在屏幕上?請幫助..如何在android活動中顯示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); 
    } 
} 

回答