【发布时间】:2015-09-03 10:11:57
【问题描述】:
我想在同一个舞台上画几个演员的副本。
这是我所做的:
// 类测试
公共类测试扩展图像{
private Sprite sprite;
private Rectangle bounds;
private final float HEIGHT = Gdx.graphics.getHeight();
public Test() {
// Sprite
Texture texture = new Texture("img.png");
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
sprite = new Sprite(texture);
// adjusting sprite size to different resolutions
float imgHeightRatio = 120.0f / 480.0f;
float imgWidthHeightRatio = sprite.getWidth() / sprite.getHeight();
float newHeight = imgHeightRatio * HEIGHT;
float newWidth = imgWidthHeightRatio * newHeight;
clockSprite.setSize(newWidth, newHeight);
// setting the size of the actor
setSize(sprite.getWidth(), sprite.getHeight());
// sprite bounds
bounds = new Rectangle();
}
public void setBounds(Rectangle bounds) {
this.bounds = bounds;
}
@Override
public void draw(Batch batch, float parentAlpha) {
// drawing sprite
batch.draw(sprite, bounds.x, bounds.y, bounds.getWidth(), bounds.getHeight());
}
} // 测试类结束
// MyStage 类
公共类 MyStage 扩展舞台 {
private Array<Test> actors;
private Rectangle rect1, rect2, rect3;
public MyStage(Test t) {
// Rectangles
rect1 = new Rectangle(0, 0, t.getWidth(), t.getHeight());
rect2 = new Rectangle(30, 30, t.getWidth(), t.getHeight());
rect3 = new Rectangle(60, 60, t.getWidth(), t.getHeight());
actors = new Array<Test>();
for(int i = 0; i < 3; i++) {
actors.add(t);
}
for(Test test : actors) {
addActor(test);
test.setBounds(rect1);
test.setBounds(rect2);
test.setBounds(rect3);
}
}
public void act(float dt) {
super.act(dt);
}
@Override
public void draw() {
super.draw();
}
public void dispose() {
super.dispose();
}
} // MyStage 类结束
【问题讨论】:
标签: libgdx