Libgdx - How to draw filled rectangle in the right place in scene2d?

前端 未结 5 1988
忘了有多久
忘了有多久 2021-01-02 02:23

I am using scene2d. Here is my code:

group.addActor(new Actor() {

    @Override
    public Actor hit(float arg0, flo         


        
5条回答
  •  迷失自我
    2021-01-02 03:03

    If your are using the ShapeRenderer don't forget using setProjectionMatrix() and setTransformMatrix() methods...

    A sample of draw circle inside an Actor on draw method :

    @Override public void draw(Batch batch, float parentAlpha) {
    
        batch.end();
    
        if (shapeRenderer == null) {
            shapeRenderer = new ShapeRenderer();
        }
    
        Gdx.gl.glEnable(GL20.GL_BLEND);
        shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
        shapeRenderer.setTransformMatrix(batch.getTransformMatrix());
        shapeRenderer.setColor(mColor.r, mColor.g, mColor.b, mColor.a * parentAlpha);
    
        shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
        shapeRenderer.circle(getX() + getWidth()/2 , getY() + getHeight()/2 , Math.min(getWidth(),getHeight())/2 );
        shapeRenderer.end();
        Gdx.gl.glDisable(GL20.GL_BLEND);
    
        batch.begin();
    }
    

提交回复
热议问题