android - LibGDX using Animations with a skin (for drag n' drop) -


i have set game actor fireflies randomly fly across screen, while glowing on , off — , user can drag them mason jar. pretty happy i've got working, i'd add bit more detail. i'd add two-step animation looks wings flapping.

i know how animation class, making use of textureatlas , textureregion. prior me heading in drag n drop direction.

my issue, think, i'm using skins, , might not play nice animations.

/////////////////// portions of code. ///////////////////

some of items declare top:

private textureatlas textureatlas; private texture texture; private textureregion[] regions = new textureregion[3]; private animation ffflapping; 

setting textureatlas:

textureatlas = new textureatlas(gdx.files.internal("player animation/player_animation.png.atlas")); texture = new texture(gdx.files.internal("player animation/player_animation.png.png")); 

setting skin:

final skin skin = new skin(); skin.addregions(textureatlas); 

doing animation:

textureregion[] ffanimation = new textureregion[2]; ffanimation[0] = (textureatlas.findregion("firefly-0")); ffanimation[1] = (textureatlas.findregion("firefly-1"));  ffflapping = new animation(0.01f, ffanimation); 

for loop create fireflies:

// ********************************************     // iterate through number of fireflies     // want draw out using fireflycount     // ********************************************     (int fireflyindex = 0; fireflyindex < fireflycount; fireflyindex++) {           // yellow firefly here         string fireflyname = "firefly" + fireflyindex;          // if replace ffflapping below object, no errors,          // no animation         skin.add(fireflyname, ffflapping);          final firefly ff = new firefly(skin, fireflyname);          system.out.println("fireflies objects:" + fireflyindex);          // not sure affected color, starts alpha @ 0         ff.setcolor(150, 150, 150, 0);         ff.setorigin(ff.getwidth()/2, ff.getheight()/2);          stage.addactor(ff);           // set in attempt continue movement if user misses target         final movetoaction actionright = new movetoaction();         final movetoaction actionleft = new movetoaction();            // setting right , left targets, random y position         float toright = gdx.graphics.getwidth() + 60;         float toleft = (gdx.graphics.getwidth() -gdx.graphics.getwidth())-60f;          // sets speed of glow, , random time firefly off, , on         float glow = mathutils.random(.5f, 1f);         float delayrandomoff = mathutils.random(2.3f, 4.5f);         float delayrandomon = mathutils.random(.5f, .9f);          // sets first variable randomly choose between toright , toleft         // assigns direction value         float randomdirection = mathutils.random.nextboolean() ? toright : toleft;         float direction = randomdirection;          sequenceaction sequence = new sequenceaction();         alphaaction aa = new alphaaction();          action alphastarton = actions.delay(delayrandomon, actions.fadeout(glow));         action alphastartoff = actions.delay(delayrandomoff, actions.fadein(glow));           // toright x value ... goes (x, y, duration)         action startright = actions.moveto(toright, mathutils.random(50, gdx.graphics.getheight() - 40), mathutils.random(10f, 45f));          // toleft x value ... goes (x, y, duration)         // 170 makes sure don't fly on top of mason jar         action startleft = actions.moveto(toleft, mathutils.random(170, gdx.graphics.getheight() - 40), mathutils.random(10f, 45f));          action faceopposite = actions.rotateby(180f);         action faceopposite2 = actions.rotateby(180f);           // endlessly loops them on screen         action loopright = actions.forever(actions.sequence(faceopposite, startright, faceopposite2, startleft));         action loopleft = actions.forever(actions.sequence(startleft, faceopposite, startright, faceopposite2));         action loopglow1 = actions.forever(actions.sequence(alphastarton, alphastartoff));         action loopglow2 = actions.forever(actions.sequence(alphastartoff, alphastarton));                   // triggering movement              if(direction == toright) {                  ff.addaction(loopright);                 ff.addaction(loopglow1);              } else {                  ff.addaction(loopleft);                 ff.addaction(loopglow2);              }                  // make each firefly draggable, , set larger size drag             draganddrop.addsource(new draganddrop.source(ff) {                 public draganddrop.payload dragstart (inputevent event, float x, float y, int pointer) {                     draganddrop.payload payload = new draganddrop.payload();                      payload.setobject("firefly captured");                     payload.setdragactor(ff);                     ff.clearactions();                     getactor().setsize(80, 80);                     // firefly freezes on drag, , enlarges ... disappears if dropped in jar                     // not visually drag cursor since part of animation.                     return payload;                 }                  // if don't drop firefly on target, make sure stays on stage                 // , goes normal size                 @override                 public void dragstop(inputevent event, float x, float y, int pointer, draganddrop.payload payload, draganddrop.target target) {                     if(target == null)                         stage.addactor(ff);                         ff.addaction(actionleft);                     getactor().setsize(50, 50);                 }             });                // make each firefly draggable, , set larger size drag             draganddrop.addsource(new draganddrop.source(ff) {                 public draganddrop.payload dragstart (inputevent event, float x, float y, int pointer) {                     draganddrop.payload payload = new draganddrop.payload();                      payload.setobject("firefly captured");                     payload.setdragactor(ff);                     ff.clearactions();                     getactor().setsize(80, 80);                     // firefly freezes on drag, , enlarges ... disappears if dropped in jar                     // not visually drag cursor since part of animation.                     return payload;                 }                  // if don't drop firefly on target, make sure stays on stage                 // , goes normal size                 @override                 public void dragstop(inputevent event, float x, float y, int pointer, draganddrop.payload payload, draganddrop.target target) {                     if(target == null)                         stage.addactor(ff);                     ff.addaction(actionleft);                     getactor().setsize(50, 50);                 }             });       } // ***** end of loop *********** 

and here's firefly code:

public class firefly extends image { private float x = mathutils.random(20, gdx.graphics.getwidth() -40); private float  y = mathutils.random(200, gdx.graphics.getheight() - 40); private float width = 70; private float height = 70;  public firefly(skin skin, string drawablename) { super(skin, drawablename); this.setbounds(x, y, width, height);  }  } // firefly 

the error i'm getting is:

com.badlogic.gdx.utils.gdxruntimeexception: no drawable, ninepatch, textureregion, texture, or sprite registered name: firefly-2 

///////////////////////////////

any tips appreciated. in meantime, i'm creating new feature branch , keeping @ it. guess need somehow make two-step animation kind of drawable.

thanks!

— bill


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -