简体   繁体   中英

Libgdx getting Animation width and height with atlas

I am starting with libgdx and I want to get the size of my animation. I have tried with:

width = atlas.findRegion("Idle_").getTexture().getWidth();

but it gives me "2048" that is the width of the spritesheet. I used the "gdx-texturepacker-3.2.0" to make all assets in one spritesheet with a .atlas file.

the .atlas file looks like this:

robotito.png
format: RGBA8888
filter: MipMap,MipMap
repeat: none
Idle_
  rotate: false
  xy: 1, 1117
  size: 567, 556
  orig: 567, 556
  offset: 0, 0
  index: 0
Idle_
  rotate: false
  xy: 1, 559
  size: 567, 556
  orig: 567, 556
  offset: 0, 0
  index: 1

I want to get that "size: 567, 556" sizes. Thank you for your help.

From the documentation on TextureRegion , these can probably help you:

  • public int getRegionHeight():
    Returns the region's height.
  • public int getRegionWidth():
    Returns the region's width.

Your "idle_" is a 2 sprite atlas, so you have to decide if you want the with of the first one or how you do it.

TextureAtlas.AtlasRegion> tex = atlas.findRegion("Idle_");

To get the width of the FIRST sprite (index 0): tex.get(0).width

if its packed you can get the packed value with: tex.get(0).packedWidth

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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