美文网首页libGdx专题
LibGdx使用模板测试

LibGdx使用模板测试

作者: 大旺旺的弟弟小旺旺 | 来源:发表于2021-10-08 14:40 被阅读0次

    一个图片中显示出一个⚪
    1.开始模板测试

    config.stencil = 8;   //开启莫把测试
    

    2.绘制

    public class SeneTest extends Group {
    
        private SpineActor spineActor;
        private Cir cir;
        public SeneTest(){
            cir = new Cir(300,300,200);
            addActor(cir);
            spineActor = new SpineActor("spine/countrypic/Australia/Australia");
            addActor(spineActor);
            spineActor.setPosition(20,100, Align.center);
            spineActor.setAnimation("1",true);
        }
    
        @Override
        public void draw(Batch batch, float parentAlpha) {
            batch.flush();
            Gdx.gl.glEnable(GL20.GL_STENCIL_TEST);
            Gdx.gl.glStencilOp(GL20.GL_KEEP, GL20.GL_KEEP, GL20.GL_REPLACE);//第一次绘制的像素的模版值 0+1 = 1
            Gdx.gl.glStencilFunc(GL20.GL_ALWAYS, 1, 0xFF);
            cir.draw(batch,parentAlpha);
            Gdx.gl.glStencilFunc(GL20.GL_EQUAL, 0x1, 0xFF);//等于1 通过测试 ,就是上次绘制的图 的范围 才通过测试。
            Gdx.gl.glStencilOp(GL20.GL_KEEP, GL20.GL_KEEP, GL20.GL_KEEP);//没有通过测试的,保留原来的,也就是保留上一次的值。
            spineActor.draw(batch,parentAlpha);
            batch.flush();
            Gdx.gl.glDisable(Gdx.gl.GL_STENCIL_TEST);
        }
    }
    

    3.cir

    
    public class Cir extends Actor {
        private float centerX;
        private float centerY;
        private float radius;
        private ShapeRenderer sr;
    
        public Cir(float x, float y, float radius) {
            this.centerX = x;
            this.centerY = y;
            this.radius = radius;
            setPosition(centerX - radius, centerY - radius);
            setSize(radius * 2, radius * 2);
            sr = new ShapeRenderer();
        }
    
        @Override
        public void act(float delta) {
            super.act(delta);
        }
    
        @Override
        public void draw(Batch batch, float parentAlpha) {
            super.draw(batch, parentAlpha);
            if (sr != null) {
                batch.end();
                sr.setProjectionMatrix(batch.getProjectionMatrix());
                sr.setTransformMatrix(batch.getTransformMatrix());
                sr.setColor(Color.valueOf("FFFFFF00"));
                sr.begin(ShapeRenderer.ShapeType.Filled);
                sr.circle(centerX, centerY, radius);
                sr.end();
                batch.begin();
            }
        }
    
        public void setRadius(float radius) {
            this.radius = radius;
        }
    
        public float getRadius() {
            return radius;
        }
    }
    
    

    效果:


    image.png

    相关文章

      网友评论

        本文标题:LibGdx使用模板测试

        本文链接:https://www.haomeiwen.com/subject/qmdxoltx.html