Transition.hx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package h3d.anim;
  2. class Transition extends Animation {
  3. public var anim1 : Animation;
  4. public var anim2 : Animation;
  5. public function new( transitionName : String, anim1 : Animation, anim2 : Animation ) {
  6. var r1 = 1, r2 = 1;
  7. while( true ) {
  8. var d = anim1.frameCount * r1 - anim2.frameCount * r2;
  9. if( d == 0 ) break;
  10. if( d < 0 ) r1++ else r2++;
  11. }
  12. super(transitionName+"("+anim1.name+","+anim2.name+")",anim1.frameCount * r1, anim1.sampling);
  13. this.anim1 = anim1;
  14. this.anim2 = anim2;
  15. }
  16. override function unbind( objectName : String ) {
  17. super.unbind(objectName);
  18. anim1.unbind(objectName);
  19. anim2.unbind(objectName);
  20. }
  21. override function setFrame( f : Float ) {
  22. super.setFrame(f);
  23. anim1.setFrame(frame % anim1.frameCount);
  24. anim2.setFrame(frame % anim2.frameCount);
  25. }
  26. override function clone(?a : Animation) : Animation {
  27. var a : Transition = cast a;
  28. if( a == null )
  29. a = new Transition(this.name.split("(")[0], anim1, anim2);
  30. super.clone(a);
  31. a.anim1 = anim1.clone();
  32. a.anim2 = anim2.clone();
  33. return a;
  34. }
  35. override function sync( decompose : Bool = false ) {
  36. if( decompose )
  37. throw "Decompose not supported on transition";
  38. anim1.isSync = anim2.isSync = false;
  39. anim1.sync();
  40. anim2.sync();
  41. }
  42. override function bind(base) {
  43. anim1.bind(base);
  44. anim2.bind(base);
  45. }
  46. override function update(dt:Float) {
  47. var rt = super.update(dt);
  48. var st = dt - rt;
  49. var tmp = st;
  50. while( tmp > 0 )
  51. tmp = anim1.update(tmp);
  52. var tmp = st;
  53. while( tmp > 0 )
  54. tmp = anim2.update(tmp);
  55. return rt;
  56. }
  57. #if !(dataOnly || macro)
  58. override function initAndBind( obj : h3d.scene.Object ) {
  59. super.initAndBind(obj);
  60. anim1.initAndBind(obj);
  61. anim2.initAndBind(obj);
  62. }
  63. #end
  64. }