From 12c8b399c80e63d1b21c75f4a25ef061a1a0daa6 Mon Sep 17 00:00:00 2001 From: KevinW1998 Date: Tue, 18 Aug 2015 18:43:19 +0200 Subject: [PATCH] Sprite api: Added loading from gifs --- LuaScriptsLibExt/sprite.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/LuaScriptsLibExt/sprite.lua b/LuaScriptsLibExt/sprite.lua index c48b09b9e..caa998bcf 100644 --- a/LuaScriptsLibExt/sprite.lua +++ b/LuaScriptsLibExt/sprite.lua @@ -165,6 +165,20 @@ function AnimationSetFactory.fromSubImages(imgs) return animationSet end +function AnimationSetFactory.fromGif(path) + local typeOfPath = type(path) + if(typeOfPath ~= "string")then + error("Arg #1 path expected string (got " .. typeOfPath .. ")", 2) + end + + local gifFrames, frameSpeed = Graphics.loadAnimatedImage(path) + if(#gifFrames == 0)then + return nil + end + + return AnimationSetFactory.fromImages(gifFrames), frameSpeed +end + -- SPRITE CLASS BEGIN @@ -379,6 +393,10 @@ function SpriteFactory.animationFromImages(...) return AnimationSetFactory.fromImages(...) end +function SpriteFactory.animationFromGif(...) + return AnimationSetFactory.fromGif(...) +end + function SpriteFactory.animationFromSubImages(...) return AnimationSetFactory.fromSubImages(...) end