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_graphics.cpp | 60 +++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) (limited to 'src/lua/modules/graphics/je_lua_graphics.cpp') diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp index 2bc3a78..4c95fa6 100644 --- a/src/lua/modules/graphics/je_lua_graphics.cpp +++ b/src/lua/modules/graphics/je_lua_graphics.cpp @@ -18,6 +18,8 @@ #include "je_lua_texture_font.h" #include "je_lua_page.h" #include "je_lua_sprite.h" +#include "je_lua_animation.h" +#include "je_lua_animator.h" using namespace std; using namespace JinEngine; @@ -25,6 +27,7 @@ using namespace JinEngine::Math; using namespace JinEngine::Graphics; using namespace JinEngine::Graphics::Fonts; using namespace JinEngine::Graphics::Shaders; +using namespace JinEngine::Graphics::Animations; using namespace JinEngine::Filesystem; namespace JinEngine @@ -739,7 +742,7 @@ namespace JinEngine quad.w = luax_rawgetnumberthenpop(L, 2, 3); quad.h = luax_rawgetnumberthenpop(L, 2, 4); int o = luax_checkinteger(L, 3); - Sprite::Origin origin = static_cast(o); + Origin origin = static_cast(o); Proxy* p = luax_newinstance(L, Jin_Lua_Sprite); p->bind(new Shared(new Sprite(graphic, quad, origin), Jin_Lua_Sprite)); } @@ -758,7 +761,7 @@ namespace JinEngine else if (n == 2) { int o = luax_checkinteger(L, 2); - Sprite::Origin origin = static_cast(o); + Origin origin = static_cast(o); Proxy* p = luax_newinstance(L, Jin_Lua_Sprite); p->bind(new Shared(new Sprite(graphic, origin), Jin_Lua_Sprite)); } @@ -800,6 +803,55 @@ namespace JinEngine return 0; } + // newAnimation([frames table, loop, speed]) + LUA_IMPLEMENT int l_newAnimation(lua_State* L) + { + int args = luax_gettop(L); + Shared* shrAnimation = new Shared(new Animation(), Jin_Lua_Animation); + if (args >= 3) + { + if (!luax_istable(L, 1)) + { + luax_typerror(L, 1, "frames table"); + return 1; + } + bool loop = luax_checkbool(L, 2); + float speed = luax_checknumber(L, 3); + int n = luax_tableidxlen(L, 1); + for (int i = 1; i <= n; ++i) + { + luax_rawgeti(L, 1, 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); + } + (*shrAnimation)->setLoop(loop); + (*shrAnimation)->setSpeed(speed); + } + Proxy* pxyAnimation = luax_newinstance(L, Jin_Lua_Animation); + pxyAnimation->bind(shrAnimation); + return 1; + } + + // newAnimator([animation]) + LUA_IMPLEMENT int l_newAnimator(lua_State* L) + { + int args = luax_gettop(L); + Shared* shrAniamtor = new Shared(new Animator(), Jin_Lua_Animator); + if (args >= 1) + { + Proxy* pxyAnimation = (Proxy*)luax_checktype(L, 1, Jin_Lua_Animation); + Shared& shrAnimtion = pxyAnimation->getShared(); + (*shrAniamtor)->setAnimation(shrAnimtion.getObject()); + (*shrAniamtor).setDependency((int)AnimatorDependency::DEP_ANIMATION, &shrAnimtion); + } + Proxy* pxyAnimator = luax_newinstance(L, Jin_Lua_Animator); + pxyAnimator->bind(shrAniamtor); + return 1; + } + /* newTextureFont(bitmap, text, color | cellw, cellh) */ LUA_IMPLEMENT int l_newTextureFont(lua_State* L) { @@ -930,6 +982,8 @@ namespace JinEngine luaopen_Shader(L); luaopen_Sprite(L); luaopen_SpriteSheet(L); + luaopen_Animation(L); + luaopen_Animator(L); luaL_Reg f[] = { /* window */ @@ -952,6 +1006,8 @@ namespace JinEngine { "newTextureFont", l_newTextureFont }, { "newSprite", l_newSprite }, { "newSpriteSheet", l_newSpriteSheet }, + { "newAnimation", l_newAnimation }, + { "newAnimator", l_newAnimator }, /* render */ { "setClearColor", l_setClearColor }, { "clear", l_clear }, -- cgit v1.1-26-g67d0