I'm trying to spawn chunks by pooling box2d Bodies, I don't know if libgdx pooling is applicable to bodies but if it is please someone explain me how to do it and what's wrong with my code.
first I created the BodyDef and Body on seperate methods:
public BodyDef createDef(){
BodyDef def = new BodyDef();
def.type = BodyDef.BodyType.StaticBody;
def.fixedRotation = true;
def.position.set(6, 6);
return(def);
}
public Body createBody(){
Body body = world.createBody(createDef());
PolygonShape shape = new PolygonShape();
shape.setAsBox(1, 1);
body.createFixture(shape, 1.0f);
shape.dispose();
return(body);
}
public void createPlatform(){
Body platform = Pools.obtain(Body.class); //then use pooling
platform = createBody(); //here I set the value equal to the return value of createBody() method
bodies.add(platform);//adding platform to the ArrayList
}
then to spawn chunks I simply call this method:
public void spawnChunk(){
createPlatform();
}
I'm so new to this I don't know what's the meaning of chunk but I know that is used on side scrolling game for spawning terrain, I get this error message:
Exception in thread "LWJGL Application" java.lang.RuntimeException: Class cannot be created (missing no-arg constructor): com.badlogic.gdx.physics.box2d.Body
at com.badlogic.gdx.utils.ReflectionPool.<init>(ReflectionPool.java:41)
at com.badlogic.gdx.utils.Pools.get(Pools.java:29)
at com.badlogic.gdx.utils.Pools.get(Pools.java:38)
at com.badlogic.gdx.utils.Pools.obtain(Pools.java:48)
at com.nivekbryan.ragingpotato.Physics.createPlatform(Physics.java:53)
at com.nivekbryan.ragingpotato.Physics.spawnChunk(Physics.java:59)
at com.nivekbryan.ragingpotato.WorldController.update(WorldController.java:17)
at com.nivekbryan.ragingpotato.MainClass.render(MainClass.java:27)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:215)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)