我认为在我的动画中加载许多纹理会导致我的游戏略有滞后,我希望我的数组纹理在 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;
}
}