Answer the question
In order to leave comments, you need to log in
Why doesn't it go to create Body through another class?
I welcome everyone.
The problem is that there is no way I can create a DynamicBody using another class.
I have a Player class:
public class Player extends Sprite {
public World world;
public Body b2body;
public Player(World world) {
this.world = world;
definePlayer();
}
// create player
public void definePlayer() {
BodyDef bdef = new BodyDef();
bdef.position.set(32 / MyGdxGame.PPM, 200 / MyGdxGame.PPM);
bdef.type = BodyDef.BodyType.DynamicBody;
b2body = world.createBody(bdef);
FixtureDef fdef = new FixtureDef();
CircleShape shape = new CircleShape();
shape.setRadius(5 / MyGdxGame.PPM);
fdef.shape = shape;
b2body.createFixture(fdef);
}
}
world = new World(new Vector2(0, -10), true);
player = new Player(world); // create player
// clear game screen
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// render game map
render.render();
// render box2dbodies
b2dr.render(world, gameCam.combined);
// set batch to draw camera
MyGdxGame.batch.setProjectionMatrix(hud.stage.getCamera().combined);
hud.stage.draw();
BodyDef bdef = new BodyDef();
bdef.position.set(32 + 10 / MyGdxGame.PPM, 200 + 10 / MyGdxGame.PPM);
bdef.type = BodyDef.BodyType.DynamicBody;
super.b2body = super.world.createBody(bdef);
FixtureDef fdef = new FixtureDef();
CircleShape shape = new CircleShape();
shape.setRadius(20 / MyGdxGame.PPM);
fdef.shape = shape;
super.b2body.createFixture(fdef);
Answer the question
In order to leave comments, you need to log in
Where is the physics update? Where is the .dispose() of a shape that is no longer needed after being passed to the fixture? Most importantly, where is the Exception? Telepaths on vacation.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question