Skip to content

Commit

Permalink
Fix animation.repeat
Browse files Browse the repository at this point in the history
  • Loading branch information
koenbok committed Sep 30, 2014
1 parent a2613e7 commit 1d521bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 72 deletions.
58 changes: 3 additions & 55 deletions 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()
a.start()
2 changes: 1 addition & 1 deletion framer/Animation.coffee
Expand Up @@ -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--
Expand Down
31 changes: 15 additions & 16 deletions test/tests/LayerAnimationTest.coffee
Expand Up @@ -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", ->
Expand Down

0 comments on commit 1d521bd

Please sign in to comment.