S
S
Sland Show2016-12-10 23:02:43
Java
Sland Show, 2016-12-10 23:02:43

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();
    }

}

But now let's move on to the main thing, to the creation of enemies. First I want to show how I created the player:
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;
    }
}

I have a PlayScreen class . There I launch the first level: I draw the player, the map, and now, I would like, the enemies. But for some reason, drawing enemies in a similar way with the player does not work out.
How I create a player: And rendering: If you don’t understand something, then here is a link to the github (to a specific class where it all happens) That is, with such a record, I don’t get the result that I want to achieve:
player = new Player(world); // create player
b2dr.render(world, gameCam.combined);
Enemy enemy;
...
...
enemy = new SimpleEnemy(world);

Here is the Enemy class which is similar to the Player class
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;
    }
}

And SimpleEnemy :
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);

    }
}

Thank you in advance for your help!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question