Results 1 to 1 of 1
  1. #1
    adamwpe is offline Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Default I added a sprite sheet but i have one question

    First of all i don't know if im in the right area of the forum.

    i added this code

    Java Code:
    public class Animator implements ApplicationListener {
    
            private static final int        FRAME_COLS = 6;         // #1
            private static final int        FRAME_ROWS = 5;         // #2
            
            Animation                       walkAnimation;          // #3
            Texture                         walkSheet;              // #4
            TextureRegion[]                 walkFrames;             // #5
            SpriteBatch                     spriteBatch;            // #6
            TextureRegion                   currentFrame;           // #7
            
            float stateTime;                                        // #8
            
            @Override
            public void create() {
                    walkSheet = new Texture(Gdx.files.internal("animation_sheet.png"));     // #9
                    TextureRegion[][] tmp = TextureRegion.split(walkSheet, walkSheet.getWidth() / 
    FRAME_COLS, walkSheet.getHeight() / FRAME_ROWS);                                // #10
                    walkFrames = new TextureRegion[FRAME_COLS * FRAME_ROWS];
                    int index = 0;
                    for (int i = 0; i < FRAME_ROWS; i++) {
                            for (int j = 0; j < FRAME_COLS; j++) {
                                    walkFrames[index++] = tmp[i][j];
                            }
                    }
                    walkAnimation = new Animation(0.025f, walkFrames);              // #11
                    spriteBatch = new SpriteBatch();                                // #12
                    stateTime = 0f;                                                 // #13
            }
    
            @Override
            public void render() {
                    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);                                            // #14
                    stateTime += Gdx.graphics.getDeltaTime();                       // #15
                    currentFrame = walkAnimation.getKeyFrame(stateTime, true);      // #16
                    spriteBatch.begin();
                    spriteBatch.draw(currentFrame, 50, 50);                         // #17
                    spriteBatch.end();
            }
    }
    I ADDED SOMETHING LIKE IT BUT IN NOT MINE im only following a example

    i would like to know how would i start the sprite sheet in a random row and col for example row 7 col 3

    Any help would be great thank you for reading

    here is a link of the original code

    https://code.google.com/p/libgdx/wiki/SpriteAnimation
    Last edited by JosAH; 09-10-2013 at 08:29 PM. Reason: added [code] ... [/code] tags

Similar Threads

  1. Flickering on a 2D Sprite
    By driiper in forum Java 2D
    Replies: 5
    Last Post: 05-06-2012, 05:30 PM
  2. import sprite
    By Bimz in forum New To Java
    Replies: 0
    Last Post: 08-28-2011, 12:15 PM
  3. Sprite-sheet vs individual images
    By David M. in forum Java Gaming
    Replies: 9
    Last Post: 08-13-2011, 08:02 PM
  4. Confisuion about sprite.getX() and sprite.getY()
    By Basit781 in forum Java Gaming
    Replies: 0
    Last Post: 01-10-2011, 06:16 AM
  5. Replies: 0
    Last Post: 08-02-2007, 12:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •