繁体   English   中英

获取LibGdx动画的宽度和高度

[英]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/T​​extureAtlas.html

TextureRegion文档: http ://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/T​​extureRegion.html

纹理文档: http : //libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/Texture.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM