[英]Superposed the sprites with libGDX
我想疊加兩個精靈,但是,當我調整窗口大小時,精靈會移動...
我的代碼:
public void resize(int width, int height) {
// TODO Auto-generated method stub
if ( height < width ){
spriteAbalone.setScale(height/700f);
billeBlanche.setScale(height/700f);
}
else{
spriteAbalone.setScale(width/700f);
billeBlanche.setScale(width/700f);
}
spriteAbalone.setPosition((width-700)/2, (height - 700)/2);
billeBlanche.setPosition((width-400)/2,(height-400)/2);
camera.setToOrtho(false, width, height);
camera.update();
}
@Override
public void show() {
// TODO Auto-generated method stub
float screenW = Gdx.graphics.getWidth();
float screenH = Gdx.graphics.getHeight();
camera = new OrthographicCamera();
camera.setToOrtho(false, screenW, screenH);
batch = new SpriteBatch();
spriteAbalone = new Sprite(new TextureRegion(new Texture(Gdx.files.internal("data/AbaloneCS5.gif")), 0, 0, 704, 704));
spriteAbalone.setSize(700 , 700);
spriteAbalone.setOrigin(704/2,704/2);
billeBlanche = new Sprite(new TextureRegion(new Texture(Gdx.files.internal("data/billeblanche.gif")),0,0,200,200));
billeBlanche.setSize(65, 65);
billeBlanche.setOrigin(704/2,704/2);
}
Sprite#setOrigin設置相對於精靈位置的原點,以進行縮放和旋轉。 在此代碼中,您為兩個精靈設置了相同的原點,盡管其中一個非常小:
spriteAbalone = new Sprite(new TextureRegion(new Texture(Gdx.files.internal("data/AbaloneCS5.gif")), 0, 0, 704, 704));
spriteAbalone.setSize(700 , 700);
spriteAbalone.setOrigin(704/2,704/2);
billeBlanche = new Sprite(new TextureRegion(new Texture(Gdx.files.internal("data/billeblanche.gif")),0,0,200,200));
billeBlanche.setSize(65, 65);
billeBlanche.setOrigin(704/2,704/2);
將billeBlanche來源更改為此:
billeBlanche.setOrigin(200/2,200/2);
同樣,在調整大小時 ,您為子畫面設置的位置始終是固定的(width-700)/ 2或(width-400)/ 2-,但是您的子畫面大小不同。 這就是他們“行動”的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.