Permalink
Browse files

added a :clone() method. fixes #1

  • Loading branch information...
1 parent 5d6c1f2 commit 5fa9adbea27f966ccfa79d1cf0b2de3a1d829743 @kikito committed Jun 6, 2012
Showing with 24 additions and 0 deletions.
  1. +4 −0 anim8.lua
  2. +20 −0 spec/anim8_spec.lua
View
@@ -215,6 +215,10 @@ local function newAnimation(mode, frames, defaultDelay, delays)
)
end
+function Animation:clone()
+ return newAnimation(self.mode, self.frames, 1, self.delays)
+end
+
function Animation:update(dt)
if self.status ~= "playing" then return end
View
@@ -317,6 +317,26 @@ describe("anim8", function()
end)
end)
+
+ describe(":clone", function()
+ it("returns a new animation with the same properties - but reset to the initial frame", function()
+ local frames = {1,2,3,4}
+ local a = newAnimation("loop", frames, 1)
+ a:update(1)
+ a:pause()
+ local b = a:clone()
+ assert_equal( "loop", b.mode)
+ assert_not_equal( frames, b.frames)
+ assert_equivalent( frames, b.frames)
+ assert_equivalent( a.delays, b.delays)
+ assert_equal( 0, b.timer)
+ assert_equal( 1, b.position)
+ assert_equal( 1, b.direction)
+ assert_equal( "playing", b.status )
+ end)
+ end)
+
+
end)
end)

0 comments on commit 5fa9adb

Please sign in to comment.