Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by niroop

when a animation is running, is it possble at any frame to reverse the animation frame flow (not flipping) ? I used rewind(), it only gets back to the first frame, is there any reverse()?

1 decade ago by sleenee

is hardcoding a problem in your specific case? cause instead of the
this.addAnim( 'whateveranimation', 0.1, [0,1,2,3] );

i would just put
this.addAnim( 'whateveranimation', 0.1, [0,1,2,3,2,1,0] );

or add a separate movement type if it's not always like that (and call when needed)
this.addAnim( 'whateveranimation2', 0.1, [3,2,1,0] );

1 decade ago by dominic

You could use JavaScript&039;s own <2> to reverse the #sequence array of the Animation. Untested:

anim.sequence.reverse();
anim.gotoFrame( anim.sequence.length - anim.frame - 1); 

The gotoFrame() call is necessary to jump to the current frame again - e.g. when an Animation with 8 frames is at frame 2, after reversing the sequence this frame number 2 becomes 8 - 2 - 1 = 5. The '-1' is because frame numbering starts at 0, so the 8th frame is frame number 7. I hope that makes sense...

1 decade ago by niroop

hi, thanks for the reply. the problem is I am not running the entire animation and then reversing it. what i want is when an animation is not yet completed its complete cycle, at any frame in its direction I want to reverse it.

I am using a speedometer for a bike and the speedometer needle has 100 frames. i can make it work in ascending order, but in middle if he releases the accelerator it directly comes back to 0km. at any moment if the button is released, it should come back with the same accel.

1 decade ago by sleenee

never tried it myself but dynamically generate the array and overwrite addAnim?

something like (not tested!):
(driving 20 per hour and releasing the button)

function GetMeMySpeed(player){
  var speedometerarray = new Array;
  for (var i = player.speed , i >=0, i--){
    speedometerarray.push(i);
  }
  return speedometerarray;
}


and in the player update function something like
if (player.buttonrealeased == 1){
  var whateverarray =  GetMeMySpeed(this);
  this.addAnim( 'whateveranimation', 0.1, whateverarray );
}

Page 1 of 1
« first « previous next › last »