Libgdx之Group

来源:互联网 发布:白光触摸屏 编程软件 编辑:程序博客网 时间:2024/05/22 18:23

Libgdx之Group

Group可以说Libgdx中非常好用的一个组件,可以把其余的Actor封装在一起,然后赋予同样的Actions或者Position等。
Group的坐标是从左下角开始的,如果将设置Group.setPosition(0,0) 那么就是从屏幕左下角开始。

下面的示例是从一篇英文博客中找到的,就直接把代码拿过来用了。其实在统一设置一些演员的属性时,我们可以把它们都封装在Group里面
从下面代码中我们可以知道,当我们旋转Group的时候2个演员是同时在选中的。
这里写图片描述这里写图片描述

下面是测试代码:

private Stage stage;    private Group group;    @Override    public void create() {        stage = new Stage();        final TextureRegion jetTexture = new TextureRegion(new Texture("jet.png"));        final TextureRegion flameTexture = new TextureRegion(new Texture("flame.png"));        final Actor jet = new Actor() {            public void draw(Batch batch, float alpha) {                batch.draw(jetTexture, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(),                        getScaleY(), getRotation());            }        };        jet.setBounds(jet.getX(), jet.getY(), jetTexture.getRegionWidth(), jetTexture.getRegionHeight());        final Actor flame = new Actor() {            public void draw(Batch batch, float alpha) {                batch.draw(flameTexture, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(),                        getScaleX(), getScaleY(), getRotation());            }        };        flame.setBounds(0, 0, flameTexture.getRegionWidth(), flameTexture.getRegionHeight());        flame.setPosition(jet.getWidth() - 25, 25);        group = new Group();        group.addActor(jet);        group.addActor(flame);        group.addAction(parallel(moveTo(200, 0, 5), rotateBy(90, 5)));        stage.addActor(group);    }    @Override    public void dispose() {        stage.dispose();    }    @Override    public void render() {        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);        stage.act(Gdx.graphics.getDeltaTime());        stage.draw();    }

这里写图片描述

1 0
原创粉丝点击