diff --git a/extras/CactusFramer/static/app.coffee b/extras/CactusFramer/static/app.coffee index 89d4581ee..dd60d3a3a 100644 --- a/extras/CactusFramer/static/app.coffee +++ b/extras/CactusFramer/static/app.coffee @@ -1,65 +1,13 @@ layer = new Layer -class AnimationGroup extends Framer.EventEmitter - - constructor: (animations=[]) -> - @setAnimations(animations) - @_currentAnimation = null - - setAnimations: (animations) -> - # Copy all animations so we can use the same one for repeat - @_animations = _.map animations, (animation) -> animation.copy() - - start: -> - @emit("start") - - _.map @_animations, (animation, index) => - - nextAnimation = @_animations[index+1] - - if nextAnimation - animation.on Events.AnimationEnd, => - nextAnimation.start() - @_currentAnimation = animation - else - animation.on Events.AnimationEnd, => - @emit("end") - @_currentAnimation = null - - @_animations[0].start() - - stop: -> - @_currentAnimation?.stop() - - -# runAnimations = (inputAnimations) -> - -# copiedAnimations = [] - -# for animation in inputAnimations -# copiedAnimations.push(animation.copy()) - -# _.map copiedAnimations, (animation, index) -> - -# nextAnimation = copiedAnimations[index+1] - -# if nextAnimation -# animation.on Events.AnimationEnd, -> -# print "Start", index -# nextAnimation.start() - -# copiedAnimations[0].start() - a = new Animation layer: layer properties: x: -> layer.x + 100 - time: 2 - - -ag = new AnimationGroup([a, a, a]) + time: 2.5 + repeat: 5 -ag.start() \ No newline at end of file +a.start() \ No newline at end of file diff --git a/framer/Animation.coffee b/framer/Animation.coffee index ad2476258..3982171bc 100644 --- a/framer/Animation.coffee +++ b/framer/Animation.coffee @@ -125,7 +125,7 @@ class exports.Animation extends EventEmitter # Todo: more repeat behaviours: # 1) add (from end position) 2) reverse (loop between a and b) if @_repeatCounter > 0 - @on "end", => + @once "end", => for k, v of @_stateA @_target[k] = v @_repeatCounter-- diff --git a/test/tests/LayerAnimationTest.coffee b/test/tests/LayerAnimationTest.coffee index b20a2f1df..ead26e23b 100644 --- a/test/tests/LayerAnimationTest.coffee +++ b/test/tests/LayerAnimationTest.coffee @@ -255,28 +255,27 @@ describe "LayerAnimation", -> layer.x.should.be.within(30, 50) done() - # describe "Repeat", -> + describe "Repeat", -> - # it "should start repeatedly", (done) -> + it "should start repeatedly", (done) -> - # layer = new Layer() + layer = new Layer() - # animation = new Animation - # layer: layer - # properties: {x: layer.x + 10} - # curve: "linear" - # time: AnimationTime - # repeat: 5 + animation = new Animation + layer: layer + properties: {x: -> layer.x + 100} + curve: "linear" + time: AnimationTime + repeat: 5 - # animation.start() + animation.start() - # c = 5 + count = 0 - # layer.on "end", -> - # print "hello" - # c-- - # if c is 3 - # done() + layer.on "end", -> + count++ + if count is animation.options.repeat + done() describe "AnimationLoop", ->