Answer the question
In order to leave comments, you need to log in
Why can't I draw new objects?
I am writing my project for release. The foundation is already there - the tile system, the GameState system, etc. But when it came to creating players, nothing really came of it. I must say right away that I am not so familiar with the framework.
Here is the main, so to speak, detail of my game:
public class MyGdxGame extends Game {
public static SpriteBatch batch;
Texture img;
public static final int V_WIDTH = 400;
public static final int V_HEIGHT = 208;
public static final float PPM = 100;
private GameLoader load;
@Override
public void create() {
batch = new SpriteBatch();
load = new GameLoader(this);
setScreen(load.getCurrentState()); // тут, как я понял, закрепляется основная сцена на фрейм
}
@Override
public void render() {
super.render();
}
@Override
public void dispose() {
batch.dispose();
img.dispose();
}
}
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);
}
// для реализации света
public Body getB2body() {
return b2body;
}
}
player = new Player(world); // create player
b2dr.render(world, gameCam.combined);
Enemy enemy;
...
...
enemy = new SimpleEnemy(world);
public abstract class Enemy extends Sprite {
World world;
Body b2body;
public Enemy(World world) {
this.world = world;
}
// create enemy
public abstract void defineEnemy();
public World getWorld() {
return world;
}
public Body getB2body() {
return b2body;
}
}
public class SimpleEnemy extends Enemy {
public SimpleEnemy(World world) {
super(world);
defineEnemy();
}
@Override
public void defineEnemy() {
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question