2017-03-08 12 views
0

私のアニメーションに多くのテクスチャをロードすると、ゲームのわずかな遅れが発生し、テクスチャアトラクションの配列テクスチャが必要になると思います。以下のコードは私のアニメーションコードです。また、アニメーションのテクスチャフレームインデックスを取得し、テクスチャインデックスが表示されている場合にはタスクを実行します。すでに、texture.atlasの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; 
      } 
     } 

答えて

0

は1 .pack に複数のアニメーションのファイルは、例えばのようなファイルの同様のタイプのためのインデックスの概念を保つ

TextureAtlas aniAtlas=new TextureAtlas("ani.pack"); 
    Array<TextureAtlas.AtlasRegion> animationFrame=aniAtlas.getRegions(); 
    float duration=.4f; 
    Animation<TextureRegion> animation=new Animation<TextureRegion>(duration,animationFrame); 

1つの別個.packファイルにアニメーションのすべてのフレームを保つのを助けることができると思います。
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"); 
+0

アニメーションが完了したら、1つのフレームを表示するにはどうすればよいですか? –

+0

テクスチャパッカー内のテクスチャが順番に並んでいません –

+0

アニメーションのレンダリングに条件を設定し、その条件に単一フレームを表示します。 – Aryan

関連する問題