Always 1st frame of the animations[SOLVED]


(billy2000) #1

Sry i have so many questions ,i just finished my exam session and my brain is still woking on power saving mode XD. The problem i encounter is as follows: I have more animations on 1 spritemap. each animation its a direction of movement.(“u”-up ,“d” -down,“l”-left “r”-right and so on ) I want for this animation to be fluent when switching directions.

Also “n” its a static animation set with speed 0 that has every frame of the animations

public function movementAndLegAnimSet():void
	{
		
		saveLegAnim = legAnim;
		saveFrame = legsMap.frame;
		
		legAnim ="";//reset leganim
		
		
		if (Input.check(Key.W)) {
			y -= 0.5;
			legAnim = legAnim + "u";
		}
		else{
		    if (Input.check(Key.S)) {
				y += 0.5;
				legAnim = legAnim + "d";
			}
		}
		if (Input.check(Key.A)) {
			x -= 0.5;
			legAnim = legAnim + "l";
		}
		else{
		    if (Input.check(Key.D)) {
			    x += 0.5;
				legAnim = legAnim + "r";
		    }
		}
		
		
		if (legAnim == "") {
			legAnim = "n"; 
			legsMap.play(legAnim);
			legsMap.frame = saveFrame;
		}
		else {
			
			legsMap.play(legAnim);
			
			if (legAnim != saveLegAnim) {
				legsMap.frame = saveFrame;
			}
		}

	}

Is u move and then stop moving its ok,it remains on the specific frame.But for some reason,if u begin to move again the animations(i mean the animation for each direction) start from the 1st frame of their frame array.

Any ideas? And again sry for so many questions >.<


(billy2000) #2

Thought saveframe is the problem and traced the values it takes on here:

                if (legAnim != saveLegAnim) {
			legsMap.frame = saveFrame;
		}

But saveframe its alright. I have no idea why legsMap resets.


(billy2000) #3

So tried to make a bit of delay when the frame should change and trace saveFrame(thought this was the problem afterall) and made it like this:

saveLegAnim = legAnim;
		
		
		legAnim ="";//reset leganim
		
		
		if (Input.check(Key.W)) {
			y -= 0.5;
			legAnim = legAnim + "u";
		}
		else{
		    if (Input.check(Key.S)) {
				y += 0.5;
				legAnim = legAnim + "d";
			}
		}
		if (Input.check(Key.A)) {
			x -= 0.5;
			legAnim = legAnim + "l";
		}
		else{
		    if (Input.check(Key.D)) {
			    x += 0.5;
				legAnim = legAnim + "r";
		    }
		}
		
		
			
		if (legAnim == "") {
			
			saveFrame = legsMap.frame;
			legAnim = "n";
			legsMap.play(legAnim);
			legsMap.frame = saveFrame;
			animTimer = 20;
		}
		else {
			
			legsMap.play(legAnim);
			
			if (saveFrame > 8 && legsMap.frame <= 8) {
				saveFrame = saveFrame-8;
			}
			if (saveFrame <= 8 && legsMap.frame > 8) {
				saveFrame = saveFrame+8;
			}
			
		}
		
		if (animTimer > 0 && legAnim != "n") {
			trace(saveFrame);
			animTimer--;
			legsMap.frame = saveFrame;
		}

And saveFrame seems ok. The only problem remains legsMap. But i have no idea what to do to it. If this helps in any way here is the LegsMap.adds:

legsMap.add("u", [1, 2, 3, 4, 5, 6, 7, 8], 15, true);
		legsMap.add("d", [8, 7, 6, 5, 4, 3, 2, 1], 15, true);
		legsMap.add("r", [9, 10, 11, 12, 13, 14, 15, 16], 15, true);
		legsMap.add("l", [16, 15, 14, 13, 12, 11, 10, 9], 15, true);
		legsMap.add("ur", [17, 18, 19, 20, 21, 22, 23, 24], 15, true);
		legsMap.add("dl", [24, 23, 22, 21, 20, 19, 18, 17], 15, true);
		legsMap.add("ul", [25, 26, 27, 28, 29, 30, 31, 32], 15, true);
		legsMap.add("dr", [32, 31, 30, 29, 28, 27, 26, 25], 15, true);
		legsMap.add("n", [0,1, 2, 3, 4, 5, 6, 7, 8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32], 0, false);

(azrafe7) #4

Not sure about it, but maybe you want legsMap.index and not legsMap.frame. By the way here’s a couple of suggestions:

  • Add a Text on screen and make it print legsMap values:
  // var declarations
  public var text:Text;
  ...
  // begin()
  var t:Entity = FP.world.addGraphic(text = new Text(), 0, 5, 15);
  t.scrollX = 0;
  t.scrollY = 0;
  ...
  // update()
  text.text = "anim: " + legsMap.currentAnim + " frame: " + legsMap.frame + " index: " + legsMap.index;
  • Instead of legsMap.add("ur", [17, 18, 19, 20, 21, 22, 23, 24], 15, true); you can do legsMap.add("ur", FP.frames(17, 24), 15, true); (also works for reverse order FP.frames(24, 17)
  • If you enable the console you can make your game play 1 frame steps and easily see what changes between one specific frame and the next

(billy2000) #5

ok did . It looks like it had to be index not frame. But what is the difference between them?


(Jacob Albano) #6

index is the index of the frame in the current animation, so if you have an animation with frames [5, 6, 7], setting index to 1 will display frame 6.

frame is the index of the frame in the whole spritemap, so setting frame to 1 will display the second frame in the whole image.


(billy2000) #7

oh i understand ty ^^ And also ty azrafe,now it works for up and right ,still same prob tho for left and down, Im gona try to solve it right now xD


(billy2000) #8

So i finaly did it with indexes and it looks something like this:

public function movementAndLegAnimSet():void
	{
		legAnim ="";//reset leganim
		
		
		if (Input.check(Key.W)) {
			y -= 0.5;
			legAnim = legAnim + "u";
		}
		else{
		    if (Input.check(Key.S)) {
				y += 0.5;
				legAnim = legAnim + "d";
			}
		}
		if (Input.check(Key.A)) {
			x -= 0.5;
			legAnim = legAnim + "l";
		}
		else{
		    if (Input.check(Key.D)) {
			    x += 0.5;
				legAnim = legAnim + "r";
		    }
		}
		
			
		if (legAnim == "") {
			
			legAnim = "n";
			legsMap.play(legAnim);
		}
		else {
			legsMap.play(legAnim);
			
			
		}
		

		if (legAnim != saveLastFrameAnim) {
			
			if (saveLastFrameAnim == "n" && legAnim == "u") {
				legsMap.index = saveLastFrameIndex;
			}
			if (saveLastFrameAnim == "u" && legAnim == "n") {
				legsMap.index = saveLastFrameIndex;
			}
			
			if (saveLastFrameAnim == "d" && legAnim == "n") {
				legsMap.index = 8 - saveLastFrameIndex -1;
			}
			if (saveLastFrameAnim == "n" && legAnim == "d") {
				legsMap.index = 8 - saveLastFrameIndex -1;
			}
			
			if (saveLastFrameAnim == "n" && legAnim == "r") {
				legsMap.index = 8+ saveLastFrameIndex;
			}
			if (saveLastFrameAnim == "r" && legAnim == "n") {
				legsMap.index =8+ saveLastFrameIndex;
			}
			
			if (saveLastFrameAnim == "l" && legAnim == "n") {
				legsMap.index =8+ 8 - saveLastFrameIndex -1;
			}
			if (saveLastFrameAnim == "n" && legAnim == "l") {
				legsMap.index =8+ 8 - saveLastFrameIndex -1;
			}
		}
		
		
		saveLastFrameAnim = legAnim;
		saveLastFrameIndex = legsMap.index;
		
		
		
	}

Ty very much for your help guys. I can always count on you XD.


(Ultima2876) #9

That index thing looks hella useful. Huh. I wish the docs were a bit more clear about that being how it works - I had no idea!


(billy2000) #10

Since im a beginner in computer science , and not English man ,i had no idea what a index is in the 1st place. Yes i checked the docs ,but what i said, i didn’t knew what a index is.But Jacob made it very clear to me ^^.And ty everyone for the help. PS: sry if im wrong but i assume u are ironic >.< PPS:When I 1st read it i thought it was a different thing.


(Ultima2876) #11

Haha, no, I really mean it - the documentation for that particular property is completely useless, native English speaker or no. I had no idea what it was and from the documentation would never have guessed really!

I can see how my comment looked like it might be sarcastic but I was being serious :stuck_out_tongue:


(billy2000) #12

Oh i feel better now XD. And yeah index is pretty useful XD.