Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8419909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:44:49+00:00 2026-06-10T02:44:49+00:00

new to android dev and andengine in general. trying to animate a sprite using

  • 0

new to android dev and andengine in general. trying to animate a sprite using the AndEngineTexturePackerExtension but im unsure how the tiledTextureRegion gets created for the animated sprite. below is what im trying which i have gotten from guides and other posts in this forum. Im creating the xml,png and java from texturepacker

private TexturePackTextureRegionLibrary mSpritesheetTexturePackTextureRegionLibrary;
private TexturePack texturePack;

 try
         {
                 TexturePackLoader texturePackLoader = new TexturePackLoader(activity.getTextureManager());
                 texturePack = texturePackLoader.loadFromAsset(activity.getAssets(), "spritesheet.xml");
                 texturePack.loadTexture();
                 mSpritesheetTexturePackTextureRegionLibrary = texturePack.getTexturePackTextureRegionLibrary();
         }
         catch (TexturePackParseException e)
         {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
         }

 TexturePackerTextureRegion textureRegion = mSpritesheetTexturePackTextureRegionLibrary.
                 get(spritesheet.00000_ID);

TiledTextureRegion tiledTextureRegion = TiledTextureRegion.create(texturePack.getTexture(),
                 textureRegion.getSourceX(), textureRegion.getSourceY(),
                 textureRegion.getSourceWidth() , textureRegion.getSourceHeight() ,
                 COLUMNS, ROWS);

AnimatedSprite sprite = new AnimatedSprite((activity.CAMERA_WIDTH - tiledTextureRegion.getWidth()) / 2,
                 (activity.CAMERA_HEIGHT - tiledTextureRegion.getHeight()) / 2,
                 tiledTextureRegion, activity.getVertexBufferObjectManager());

the problem is that i dont understand where the values from COLUMNS and ROWS comes from? the sprite sheet itself has uneven rows and columns as it includes rotated sprites etc. So im confused as to where these values come from. Any help on getting this working would be great thanks

edit: Ok i can get the sprite sheet animation working if i just use the basic algorithm within texture packer and not the MaxRects algorithm. But this doesnt make use of all the space within a sheet so i would rather get it working using a MaxRects generated sprite sheet. I see with in the xml that it pass a bool for being rotated or not so the information is there to make this work i just cant figure out how. how do i use a texturepackertexture region to make an animated sprite when some of the textures are rotated on the sheet

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:44:50+00:00Added an answer on June 10, 2026 at 2:44 am

    TexturePacker doesn’t know how much columns and rows have your sprites, not even if they are tiled or not, it just packs everything into a single spritesheet (png file for example). Also, its goal isn’t to create TiledSprites from separated Sprites.

    So, in order to get back a TiledSprite (or AnimatedSprite) from a spritesheet, you have to know how much columns and rows (it can be hardcoded somewhere) it had before being put into the spritesheet, since TexturePacker won’t give you that kind of information.

    I personally use a TextureRegionFactory which looks like this:

    public class TexturesFactory {
    
        public static final String SPRITESHEET_DIR = "gfx/spritesheets/";
        public static final String TEXTURES_DIR = SPRITESHEET_DIR+"textures/";
    
        private TexturePack mTexturePack;
        private TexturePackTextureRegionLibrary mTextureRegionLibrary;
    
        /**
         * 
         * @param pEngine
         * @param pContext
         * @param filename
         */
        public void loadSpritesheet(Engine pEngine, Context pContext, String filename) {
    
            try {
                this.mTexturePack = new TexturePackLoader(
                        pEngine.getTextureManager(), TEXTURES_DIR).loadFromAsset(
                                pContext.getAssets(), filename);
    
                this.mTextureRegionLibrary = this.mTexturePack.getTexturePackTextureRegionLibrary();
                this.mTexturePack.getTexture().load();
    
            } catch (TexturePackParseException ex) {
                Log.e("Factory", ex.getMessage(), ex);
            }
        }
    
        public TextureRegion getRegion(int id) {
            return this.mTextureRegionLibrary.get(id);
        }
    
        public TiledTextureRegion getTiled(int id, final int rows, final int columns) {
    
            TexturePackerTextureRegion packedTextureRegion = this.mTextureRegionLibrary.get(id);
    
            return TiledTextureRegion.create(
                    packedTextureRegion.getTexture(), 
                    (int) packedTextureRegion.getTextureX(), 
                    (int) packedTextureRegion.getTextureY(), 
                    (int) packedTextureRegion.getWidth(), 
                    (int) packedTextureRegion.getHeight(), 
                    columns, 
                    rows);
        }
    }
    

    Edit: About the rotated problem, it is written inside the xml generated by TexturePacker, so you can get it by calling

    TexturePackerTextureRegion packedTextureRegion = this.mTextureRegionLibrary.get(id);
    packedTextureRegion.isRotated()
    

    Then, you can create the tiledTextureRegion according to that value with:

    TiledTextureRegion.create(
                    packedTextureRegion.getTexture(), 
                    (int) packedTextureRegion.getTextureX(), 
                    (int) packedTextureRegion.getTextureY(), 
                    (int) packedTextureRegion.getWidth(), 
                    (int) packedTextureRegion.getHeight(), 
                    columns, 
                    rows,
                    packedTextureRegion.isRotated());
    

    Also, I hope it is clear to you that TexturePacker isn’t meant to create tiled sprites. You must create your tiled sprites (nice fit or rows and columns) before using TexturePacker.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im new to android dev and using andengine and ive just come across a
I am quite new to Android dev, but not Java dev, so doing the
Hello I am new to android dev and admob. I am trying to make
I'm new to Android Dev, so please help me out. I'm trying to start
I'm new to Android dev. There's a very pretty state diagram of the MediaPlayer
I'm pretty new to Android dev and still working out a lot of things.
i am creating a new android application.i am using the table layout. I have
I am very new to Android. I am trying to build inflate a context
I just started to play with android dev and java+eclipse is pretty new to
I've been trying to get a handle on Dialogs. I read the android dev

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.