簡體   English   中英

LibGDX中的紋理圖集

[英]Texture atlas in LibGDX

我正在嘗試加載png文件,但是我不知道為什么它不起作用,因為我已經檢查了文件路徑並使用TexturePacker制作了紋理圖集。 同一路徑中的其他圖像也可以正常工作。 任何幫助將不勝感激。

SpriteBatch batch;
Texture img, img2, img4;
private Player player, player2;
private Texture start, continued;
TextureRegion my, my2, my3;
TextureRegionDrawable myt, myt2, myt3;
Button button, button2;
Stage stage, stage2;
String fonte, starte, opcoes;
BitmapFont yesa, funciona;
Image ima;
Texture img3;
Sprite spider;
TextureAtlas textatlas;
FileHandle f;


 public void create(){

 Stage stage = new Stage();
    OrthographicCamera camera = new OrthographicCamera();
    camera.setToOrtho(false, 800, 480);
    batch = new SpriteBatch();
    textatlas = new TextureAtlas("TA/Agorafunfa.png");
    TextureAtlas.AtlasRegion a = textatlas.findRegion("spider");
    spider = new Sprite(a);
    //player2 = new Player("spider.png", Info.WIDTH / 2, Info.HEIGHT / 2);
    player = new Player("playerr.png", Info.WIDTH / 2, Info.HEIGHT / 2);
    img = new Texture("Captura.PNG");
    myt = new TextureRegionDrawable(my);
    yesa = new BitmapFont(Gdx.files.internal("yesa.fnt"));
    fonte = "Escape Planet";
    img2 = new Texture("comeca.png");
    img4 = new Texture("comeca.png");
    img3 = new Texture("saturno.png");
    ima = new Image(img3);
    myt2 = new TextureRegionDrawable(my2);
    funciona = new BitmapFont(Gdx.files.internal("yesa.fnt"));
    starte = "Começar";
    myt3 = new TextureRegionDrawable(my3);
    opcoes = "Opções";
    TextureRegion tx = new TextureRegion(img2);
    Drawable dr = new TextureRegionDrawable(tx);
 }

發生以下錯誤:

Exception in thread "LWJGL Application" 
 com.badlogic.gdx.utils.GdxRuntimeException: Error reading pack file: 
 TA/Agorafunfa.png
 at com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.<init> 
 (TextureAtlas.java:187)
 at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:231)
 at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:226)
 at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:216)
 at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init> 
(TextureAtlas.java:211)
 at com.mygdx.game.MyGdxGame.create(MyGdxGame.java:63)
 at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop
(LwjglApplication.java:149)
at 
com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run
(LwjglApplication.java:126)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Invalid line: 
at 
com.badlogic.gdx.graphics.g2d.TextureAtlas.readTuple(TextureAtlas.java:443)
at com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.<init> 
(TextureAtlas.java:115)... 7 more

創建紋理圖集后,您應該獲得2個文件: .png圖像和具有相同名稱和擴展名的.atlas文件,例如.atlas.pack

因此,您應該使用此文件。

大概:

textatlas = new TextureAtlas("TA/Agorafunfa.atlas"); // Or Agorafunfa.pack or simillar

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM