[英]Get width and height of LibGdx animation
使用LibGdx動畫時如何獲得單個幀的寬度和高度?
tallAnim = new Animation(1/10f, atlas.findRegion("runner1"), atlas.findRegion("runner2"), atlas.findRegion("runner3"), atlas.findRegion("runner4"));
shortAnim = new Animation(1/10f, atlas.findRegion("short_runner1"), atlas.findRegion("short_runner2"), atlas.findRegion("short_runner3"), atlas.findRegion("short_runner4"));
animation = tallAnim;
我在這兩個動畫之間切換,當我檢查碰撞時,我需要知道當前動畫幀的確切寬度/高度。
我通常如何處理:
public Rectangle getBounds(){
return new Rectangle(positionX, positionY, sprite.getWidth(), sprite.getHeight());
}
方法atlas.findRegion("path/goes/here")
返回TextureRegion。 TextureRegion具有region.getTexture region.getTexture()
方法。 Texture具有tex.getWidth()
和tex.getHeight()
方法。 假設這些幀的寬度相同,您應該能夠說出類似atlas.findRegion("path/goes/here").getTexture().getWidth()
和atlas.findRegion("path/goes/here").getTexture().getHeight()
。 否則,您將需要某種方式來跟蹤當前的幀並根據當前幀獲取寬度和高度。
我猜,您的方法現在應該類似於:
public Rectangle getBounds() {
return new Rectangle(posX, posY, atlas.findRegion("path/goes/here").getTexture().getWidth(), atlas.findRegion("path/goes/here").getTexture().getHeight())
}
我將提供一些指向每個類的鏈接,以便您可以自己瀏覽並查看它們還有哪些其他方法。
TextureAtlas文檔: http ://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/TextureAtlas.html
TextureRegion文檔: http ://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/TextureRegion.html
紋理文檔: http : //libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/Texture.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.