Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added a :clone() method. fixes #1

  • Loading branch information...
commit 5fa9adbea27f966ccfa79d1cf0b2de3a1d829743 1 parent 5d6c1f2
Enrique García authored
4  anim8.lua
@@ -215,6 +215,10 @@ local function newAnimation(mode, frames, defaultDelay, delays)
215 215
   )
216 216
 end
217 217
 
  218
+function Animation:clone()
  219
+  return newAnimation(self.mode, self.frames, 1, self.delays)
  220
+end
  221
+
218 222
 function Animation:update(dt)
219 223
   if self.status ~= "playing" then return end
220 224
 
20  spec/anim8_spec.lua
@@ -317,6 +317,26 @@ describe("anim8", function()
317 317
 
318 318
       end)
319 319
     end)
  320
+
  321
+    describe(":clone", function()
  322
+      it("returns a new animation with the same properties - but reset to the initial frame", function()
  323
+        local frames = {1,2,3,4}
  324
+        local a = newAnimation("loop", frames, 1)
  325
+        a:update(1)
  326
+        a:pause()
  327
+        local b = a:clone()
  328
+        assert_equal(      "loop", b.mode)
  329
+        assert_not_equal(  frames, b.frames)
  330
+        assert_equivalent( frames, b.frames)
  331
+        assert_equivalent( a.delays, b.delays)
  332
+        assert_equal(      0, b.timer)
  333
+        assert_equal(      1, b.position)
  334
+        assert_equal(      1, b.direction)
  335
+        assert_equal(     "playing", b.status )
  336
+      end)
  337
+    end)
  338
+
  339
+
320 340
   end)
321 341
 
322 342
 end)

0 notes on commit 5fa9adb

Please sign in to comment.
Something went wrong with that request. Please try again.