Permalink
Browse files

Fix animation.repeat

  • Loading branch information...
koenbok committed Sep 30, 2014
1 parent a2613e7 commit 1d521bd1f1c7c36cffe418ed954f3887945140ad
Showing with 19 additions and 72 deletions.
  1. +3 −55 extras/CactusFramer/static/app.coffee
  2. +1 −1 framer/Animation.coffee
  3. +15 −16 test/tests/LayerAnimationTest.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()
a.start()
View
@@ -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--
@@ -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", ->

0 comments on commit 1d521bd

Please sign in to comment.