Support for image animations.

This commit is contained in:
emb
2015-11-17 21:57:52 -06:00
parent 4e7b696730
commit 2621fb7c5f
5 changed files with 105 additions and 65 deletions

View File

@@ -295,3 +295,59 @@ int LuaImage::setLayer(lua_State *l)
return 0;
}
int LuaImage::animate(lua_State *l)
{
Image *i = (Image *)lua_tointeger(l, 1);
bool loop = (lua_toboolean(l, 2) != 0);
i->animate(loop);
return 0;
}
int LuaImage::addAnimation(lua_State *l)
{
Image *i = (Image *)lua_tointeger(l, 1);
if(!i) return 0;
float duration = (float)lua_tonumber(l, 2);
if (!lua_istable(l, 3)) {
return 0;
}
ComponentData newInfo;
newInfo.clearMask(COMPONENT_DATA_ALL_MASK);
lua_pushstring (l, "x");
lua_gettable(l, -2);
if(!lua_isnil(l, -1))
{
newInfo.setMask(COMPONENT_DATA_X_MASK);
newInfo.x = (int)luaL_optinteger(l, -1, i->info.x);
}
lua_pop(l, 1);
lua_pushstring (l, "y");
lua_gettable(l, -2);
if(!lua_isnil(l, -1))
{
newInfo.setMask(COMPONENT_DATA_Y_MASK);
newInfo.y = (int)luaL_optinteger(l, -1, i->info.y);
}
lua_pop(l, 1);
lua_pushstring (l, "alpha");
lua_gettable(l, -2);
if(!lua_isnil(l, -1))
{
newInfo.setMask(COMPONENT_DATA_ALPHA_MASK);
newInfo.alpha = (float)luaL_optnumber(l, -1, i->info.alpha);
}
lua_pop(l, 1);
newInfo.duration = duration;
i->addAnimation(newInfo);
return 0;
}