From 07022c42a925d4d0c23ab31f0e75883766ce773a Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 21 Nov 2018 21:12:42 +0800 Subject: =?UTF-8?q?*=E5=8A=A8=E7=94=BB=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lua/modules/graphics/je_lua_animation.cpp | 67 ++++++++++++++++++++------- 1 file changed, 50 insertions(+), 17 deletions(-) (limited to 'src/lua/modules/graphics/je_lua_animation.cpp') diff --git a/src/lua/modules/graphics/je_lua_animation.cpp b/src/lua/modules/graphics/je_lua_animation.cpp index 1db66f1..cc82685 100644 --- a/src/lua/modules/graphics/je_lua_animation.cpp +++ b/src/lua/modules/graphics/je_lua_animation.cpp @@ -35,34 +35,67 @@ namespace JinEngine return 0; } - LUA_IMPLEMENT int l_render(lua_State* L) + // addFrame(frame) + LUA_IMPLEMENT int l_addFrame(lua_State* L) { - SharedAnimation sprite = checkAnimation(L); - float x = luax_checknumber(L, 2); - float y = luax_checknumber(L, 3); - float sx = luax_checknumber(L, 4); - float sy = luax_checknumber(L, 5); - float r = luax_checknumber(L, 6); - sprite->render(x, y, sx, sy, r); + SharedAnimation shrAnimation = checkAnimation(L); + Proxy* pxySprite = (Proxy*)luax_checktype(L, 2, Jin_Lua_Sprite); + Shared& shrSprite = pxySprite->getShared(); + shrAnimation->addFrame(shrSprite.getObject()); + int i = shrAnimation->getFrameCount() - 1; + shrAnimation.setDependency((int)AnimationDependency::DEP_SPRITES + i, &shrSprite); return 0; } - LUA_IMPLEMENT int l_getSize(lua_State* L) + // addFrames(frames table) + LUA_IMPLEMENT int l_addFrames(lua_State* L) { - SharedAnimation sprite = checkAnimation(L); - //Vector2 size = sprite->getSize(); - //luax_pushinteger(L, size.x); - //luax_pushinteger(L, size.y); + SharedAnimation shrAnimation = checkAnimation(L); + if (!luax_istable(L, 2)) + { + luax_typerror(L, 2, "sprites table"); + return 1; + } + int n = luax_tableidxlen(L, 2); + for (int i = 1; i <= n; ++i) + { + luax_rawgeti(L, 2, i); + Proxy* pxySprite = (Proxy*)luax_checktype(L, -1, Jin_Lua_Sprite); + Shared& shrSprite = pxySprite->getShared(); + shrAnimation->addFrame(shrSprite.getObject()); + int index = shrAnimation->getFrameCount() - 1; + shrAnimation.setDependency((int)AnimationDependency::DEP_SPRITES + index, &shrSprite); + } + return 0; + } + + LUA_IMPLEMENT int l_isLoop(lua_State* L) + { + SharedAnimation shrAnimation = checkAnimation(L); + bool loop = shrAnimation->isLoop(); + luax_pushboolean(L, loop); + return 1; + } + + LUA_IMPLEMENT int l_getSpeed(lua_State* L) + { + SharedAnimation shrAnimation = checkAnimation(L); + float speed = shrAnimation->getSpeed(); + luax_pushnumber(L, speed); return 1; } LUA_EXPORT void luaopen_Animation(lua_State* L) { luaL_Reg methods[] = { - { "__gc", l_gc }, - { "render", l_render }, - { "getSize", l_getSize }, - { 0, 0 } + { "__gc", l_gc }, + { "addFrame", l_addFrame }, + { "addFrames", l_addFrames }, + { "isLoop", l_isLoop }, + { "getSpeed", l_getSpeed }, + { "getFrameCount", l_getSpeed }, + //{ "getFrame", l_getFrame }, + { 0, 0 } }; luax_newtype(L, Jin_Lua_Animation, methods); } -- cgit v1.1-26-g67d0