0
我在想扩展org.jbox2d.dynamics.Body
我已经设置Rectangle
延长org.jbox2d.dynamics.Body
,并将其设置为DYNAMIC
一个问题,但Rectangle
不会移动。
如果我创建了多个Rectangle
's,它们都位于相同的位置,即(0.0f,0.0f),为什么?正确的方式来扩展org.jbox2d.dynamics.Body
Rectangle
定义为:
public class Rectangle extends Shape {
private PolygonShape blockShape;
private Body body;
private float width;
private float height;
public Rectangle (
Vec2 centerPoint,
float angle,
float width, float height,
BodyType bt,
float density, float friction, float restitution,
World world,
BodyDef bd){
super(bd,world);
this.width = width;
this.height = height;
blockShape = new PolygonShape();
blockShape.setAsBox(this.width, this.height);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = blockShape;
fixtureDef.density = density;
fixtureDef.friction = friction;
fixtureDef.restitution = restitution;
this.bodydef.type = BodyType.DYNAMIC;
this.bodydef.position.set(centerPoint.x, centerPoint.y);
this.bodydef.angle = angle;
world.createBody(this.bodydef);
createFixture(fixtureDef);
setType(bt);
};
Shape
具有遵循定义:
public abstract class Shape extends org.jbox2d.dynamics.Body{
protected World world;
protected BodyDef bodydef;
public Shape(BodyDef bd, World w) {
super(bd, w);
this.world = w;
this.bodydef = bd;
}
protected abstract void update();
protected abstract void draw(GLAutoDrawable gLDrawable);
}
在Level.java
延伸org.jbox2d.dynamics.World
创建一个Rectangle
并调用Rectangle.draw(gLDrawable)
new Rectangle(
new Vec2(1.0f,1.0f),//Vec2(x,y)
0.0f, //angle
2.0f, //width
2.0f, //height
BodyType.DYNAMIC, //bodyType
0.5f, //density
0.5f, //friction
0.5f, //restitution
this, //world
new BodyDef())); //BodyDef