好的,这是我的代码(这只是使用 DebugDraw 的测试):
package test;
import org.jbox2d.callbacks.*;
import org.jbox2d.collision.shapes.*;
import org.jbox2d.common.*;
import org.jbox2d.dynamics.*;
public class Main {
private static DebugDraw debugDraw;
public static DebugDraw getDebugDraw() {
return debugDraw;
}
public static void main(String[] args) {
Vec2 gravity = new Vec2(0,-10);
boolean doSleep = true;
World world = new World(gravity,doSleep);
BodyDef groundBodyDef = new BodyDef();
groundBodyDef.position.set(0, -10);
Body groundBody = world.createBody(groundBodyDef);
PolygonShape groundBox = new PolygonShape();
groundBox.setAsBox(50,10);
groundBody.createFixture(groundBox, 0);
// Dynamic Body
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position.set(0, 4);
Body body = world.createBody(bodyDef);
PolygonShape dynamicBox = new PolygonShape();
dynamicBox.setAsBox(1, 1);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = dynamicBox;
fixtureDef.density=1;
fixtureDef.friction=0.3f;
body.createFixture(fixtureDef);
// Setup world
float timeStep = 1.0f/60.0f;
int velocityIterations = 6;
int positionIterations = 2;
// Run loop
for (int i = 0; i < 60; ++i)
{
world.step(timeStep, velocityIterations, positionIterations);
Vec2 position = body.getPosition();
float angle = body.getAngle();
debugDraw.setFlags(debugDraw.e_shapeBit);
world.setDebugDraw(debugDraw);
System.out.println(i+": X: "+position.x+" Y: "+position.y+" ANGLE: "+angle);
}
}
}
当我运行此代码时,我得到:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NullPointerException
at test.Main.main(Main.java:49)
Java Result: 1
有谁知道是什么原因造成的,我应该怎么做?我尝试过谷歌搜索,但我只能找到 Slick2D,我不想植入整个库来测试一个简单的测试应用程序。