3
votes

I am trying to override my Player class that extends Actor draw method but I am receiving an error saying

The method draw(SpriteBatch, float) of type Player must override or implement a supertype method

Why can I not override the default draw method from the class Actor? Here is my code from the Player class.

public class Player extends Actor {
    @Override
    public void draw(SpriteBatch batch, float parentAlpha) {
        Gdx.app.log(getName(), "Drawing player");
    }

    public Player() {
        setName("mainPlayer");

        playerBounds = new Rectangle(100, 100, 32, 32);
    }
}

Here is my code from the class with the Stage that is being drawn.

public class Mainscreen implements Screen {
    // Class TAG
    private static final String TAG = "Main Screen";

    // Screen Variable(s)
    private Awakening g;
    private SpriteBatch sprBatch;
    private OrthographicCamera gameCamera;
    private Player mainPlayer;

    // Screen Stage(s)
    private sMain sMain;

    @Override
    public void dispose() {
        sprBatch.dispose();
        sMain.dispose();
    }

    @Override
    public void hide() {
        g.inputController.removeProcessor(sMain);

        dispose();
    }

    public Mainscreen(Awakening game){
        g = game;

        sMain = new sMain(g, g.configMgr.getWidth(), g.configMgr.getHeight(), true);

        gameCamera = new OrthographicCamera();
        gameCamera.setToOrtho(false, sMain.getWidth(), sMain.getHeight());

        mainPlayer = new Player(g, gameCamera);
        g.setPlayer(mainPlayer);

        sprBatch = new SpriteBatch();

        g.mapMgr.setMap(g, gameCamera, "TestMap", mainPlayer);

        sMain.addActor(mainPlayer);
    }

    @Override
    public void pause() {g.togglePause(true);g.debugOut(TAG, "pause()");}

    @Override
    public void render(float delta) {
        if(!g.isPaused()){

            sMain.act(delta);

            Gdx.gl.glClearColor(.125f, .125f, .125f, 0);
            Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

            gameCamera.update();

            g.mapMgr.updateNPCS();

            sprBatch.setProjectionMatrix(gameCamera.combined);
            sprBatch.begin();
            g.mapMgr.draw(gameCamera, new int[] {0,1});

            sMain.draw(); // Draw player/NPCs

            //g.getPlayer().draw(sprBatch, 0f);

            g.mapMgr.drawCollisionRectangles(gameCamera);
            sprBatch.end();
        }
    }

    @Override
    public void resize(int width, int height) {g.debugOut(TAG,"resize("+width+","+height+")");}

    @Override
    public void resume() {g.togglePause(false);g.debugOut(TAG, "resume()");}

    @Override
    public void show() {
        g.debugOut(TAG, "show()");

        g.inputController.addProcessor(sMain);
        g.updateInput();
    }
}

I am not sure what's going on but was pretty sure I could override draw before.

1

1 Answers

7
votes

You must override it like this:

@Override
public void draw(Batch batch, float parentAlpha) {
    Gdx.app.log(getName(), "Drawing player");
}

Change the SpriteBatch to Batch. Reference Actor#draw