LibGDX Actor绘制覆盖

时间:2013-12-27 00:28:51

标签: java android libgdx

我正在尝试覆盖扩展Actor绘制方法的Player类,但是我收到错误说

  

Player类型的draw(SpriteBatch,float)方法必须覆盖或   实现超类型方法

为什么我不能覆盖类draw中的默认Actor方法?这是我在Player类中的代码。

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

以下是我正在绘制舞台的类的代码。

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

我不确定发生了什么,但我很确定我之前可以覆盖抽奖。

1 个答案:

答案 0 :(得分:7)

你必须像这样覆盖它:

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

SpriteBatch 更改为批处理。参考Actor#draw