2017-03-08 3 views
0

Ich denke, das Laden vieler Texturen in meiner Animation verursachen die leichte Verzögerung in meinem Spiel, und ich möchte meine Array-Texturen in einem TextureAtlas. Der folgende Code ist mein Animationscode und er wird auch den Textur-Frame-Index in der Animation erhalten und eine Aufgabe ausführen, wenn der Textur-Index angezeigt wird ...., ich habe bereits eine .pack-Datei namens shot.pack für texture atlas, aber ich wusste nicht, wie man es anwendet und es so macht. Ich hoffe, dass jemand helfen kannTexturen Textur Atlas und Animation

 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; 
      } 
     } 

Antwort

0

Halten Sie alle Frame der Animation in einer Separate .pack Datei

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

Mehrere Animations-Datei in einem .pack Indizierungskonzept halten für eine ähnliche Art von Datei wie zB.
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); 

Verwenden können AssetManger verwenden und Ihre TextureAtlas auf diese Weise laden:

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

Wie kann ich ein einzelnes Bild anzeigen, wenn die Animation fertig ist? –

+0

Meine Textur in Textur Packer war nicht in Ordnung –

+0

setzen Sie eine Bedingung in Rendering für Animation und zeigen Einzelbild über diese Bedingung. – Aryan