Java – libgdx actor draw overlay

I tried to override my player class, which extends the actor drawing method, but I received an error saying

Why can't I override the default draw method from class actor? This is my code in 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);
    }
}

This is the code in the class I'm drawing the stage

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,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'm not sure what happened, but I'm sure I can cover the previous lottery

Solution

You have to cover it like this:

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

Change SpriteBatch to batch Reference actor#draw

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>