[英]Textures to texture atlas and animation
我認為動畫中許多紋理的加載會導致游戲中的輕微滯后,我希望將陣列紋理放入TextureAtlas中。 下面的代碼是我的動畫代碼,如果顯示了紋理索引,它還將在動畫中獲取紋理框架索引並執行任務....,我已經有了一個名為shot.pack的.pack文件,用於紋理圖集,不知道如何應用它,使它像這樣。 我希望有人能幫幫忙
Texture[] shot;
//At CONSTRUCTOR
shot = new Texture[21];
for(int i=0; i <21; i++){
if(i == 19 || i==20 ){
shot[i]=new Texture("s18.png");
}
else {
shot[i] = new Texture("s" + Integer.toString(i) + ".png");
}
}
//animation
animation = new Animation(1/19f,shot);
//@render METHOD
sb.draw((Texture) animation.getKeyFrame(timePassed, false), ShootingTreys.WIDTH * 0.03f, ShootingTreys.HEIGHT * 0.03f, (ShootingTreys.WIDTH * 1 / 6), (ShootingTreys.HEIGHT / 2) + (ShootingTreys.HEIGHT * 0.13f));
if (animation.getKeyFrameIndex(timePassed) == 20) {
isShotDelay = true;
shotDelay += Gdx.graphics.getDeltaTime();
if (shotDelay >= 0.2f || ball.getBall().getY() < ShootingTreys.HEIGHT * 0.2f) {
touch = false;
timePassed = 0;
shotDelay = 0;
isShotDelay = true;
//for missed ball
colide = false;
}
}
將所有動畫幀保存在一個單獨的.pack文件中
TextureAtlas aniAtlas=new TextureAtlas("ani.pack");
Array<TextureAtlas.AtlasRegion> animationFrame=aniAtlas.getRegions();
float duration=.4f;
Animation<TextureRegion> animation=new Animation<TextureRegion>(duration,animationFrame);
一個.pack中的多個Animation的文件保留了類似類型文件的索引概念,例如。
bird_0.png,bird_1.png,.....
cat_0.png,cat_1.png,.....
TextureAtlas multiAniAtlas=new TextureAtlas("ani.pack");
Array<TextureAtlas.AtlasRegion> birdFrames=multiAniAtlas.findRegions("bird");
float duration1=.55f;
Animation<TextureRegion> birdAnimation=new Animation<TextureRegion>(duration1,birdFrames);
使用可以使用AssetManger並通過以下方式加載TextureAtlas:
AssetManager assetManager=new AssetManager();
assetManager.setLoader(TextureAtlas.class, new TextureAtlasLoader(new InternalFileHandleResolver()));
assetManager.load("ani.pack", TextureAtlas.class);
assetManager.finishLoading();
TextureAtlas atlas=assetManager.get("ani.pack");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.