libgdx - Multiple animations into one object Animation -


i'm trying use animation sheet in player class, i'm having doubts situation. following documentation (https://github.com/libgdx/libgdx/wiki/2d-animation) talks 2d animation, show single type of animation, in case, walk animation. context different, have 3 types of animation: idle, running , climbing. wonder if it's possible hold types of animation in unique animation object or must create 3 objects each? trie find equal on stackoverflow , google, found nothing.

this did private method loadanimations():

private void loadanimations() {     // player animations sheet     texture playersheet = assets.manager.get(assets.playersheet);      // list of texture regions hold animations     textureregion[][] tmp = textureregion.split(playersheet, playersheet.getwidth() / player_frame_cols, playersheet.getheight() / player_frame_rows);      // put textures texture region 1-d texture region     int index = 0;     textureregion[] walkframes = new textureregion[player_frame_cols * player_frame_rows];     (int = 0; < player_frame_rows; i++) {         (int j = 0; j < player_frame_cols; j++) {             walkframes[index++] = tmp[i][j];         }     }     this.runanimation = new animation(frames_durtion, walkframes); } 

and player proprietes:

private animation idleanimation, runanimation, climbanimation; private textureregion currentframe; 

what in case? thank you.

to take advantage of methods in animation class, i'd create 3 separate animation objects, 1 each "state" (idle, run, climb). code have (and in tutorial) loads animation textures 1 of states. you'd need similar 3 of animation textures create 3 different animation objects.

then in render method, based on "state" character in, choose animation render.

ex, in below, line

currentframe = walkanimation.getkeyframe(statetime, true); 

would choose animation (idleanimation, runanimation, climbanimation) you'd render based on character doing. (you may need play around statetime values when switching between animations), understand i'm suggesting.

@override     public void render() {         gdx.gl.glclear(gl20.gl_color_buffer_bit | gl20.gl_depth_buffer_bit);                                 statetime += gdx.graphics.getdeltatime();                    currentframe = walkanimation.getkeyframe(statetime, true);            spritebatch.begin();         spritebatch.draw(currentframe, 50, 50);                      spritebatch.end();     } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -