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
- Libgdx之Group
- Libgdx 之Group视图裁剪
- libgdx之粒子特效
- libgdx之RevoluteJointDef关节
- libgdx之PrismaticJoint关节
- libgdx之FrictionJoint关节
- libgdx之WeldJointDef关节
- libgdx 之 tiled地图
- 9.6、Libgdx之罗盘
- 9.7、Libgdx之振动器
- Libgdx 之贝塞尔曲线
- libgdx API之提示
- Libgdx之Texture TextureRegion
- Libgdx之TexturePacker TextureAtlas
- Libgdx 之BitmapFont 字体
- Libgdx之Animation 动画
- Libgdx之Label Image
- Libgdx 之CheckBox ScrollPane
- 语义和语法结构之间的关系
- 关于浏览器的问题
- javaType字符数组与jdbcType字符串转换(mybatis)
- [Leetcode]258. Add Digits
- linux select与poll的区别
- Libgdx之Group
- 从头认识多线程-3.2 使用volatile声明的变量的写操作是非原子性的
- 日常生活
- TrueCrypt 变废为宝-银行U盾
- maven
- Bitset类总结
- Arrays类的copyOf与System类的arrayscopy()的区别
- windows64 CPU python2.7 安装theano & keras
- 梳理caffe代码relu_layer(二十一)