aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/graphics/je_lua_graphics.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-11-21 21:12:42 +0800
committerchai <chaifix@163.com>2018-11-21 21:12:42 +0800
commit07022c42a925d4d0c23ab31f0e75883766ce773a (patch)
tree5aa5fc533534ab987c954a30fa11fc124c50a755 /src/lua/modules/graphics/je_lua_graphics.cpp
parentf440f7fb52ca62715504e4a3c7076456de40f7b8 (diff)
*动画系统
Diffstat (limited to 'src/lua/modules/graphics/je_lua_graphics.cpp')
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.cpp60
1 files changed, 58 insertions, 2 deletions
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<Sprite::Origin>(o);
+ Origin origin = static_cast<Origin>(o);
Proxy* p = luax_newinstance(L, Jin_Lua_Sprite);
p->bind(new Shared<Sprite>(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<Sprite::Origin>(o);
+ Origin origin = static_cast<Origin>(o);
Proxy* p = luax_newinstance(L, Jin_Lua_Sprite);
p->bind(new Shared<Sprite>(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<Animation>* shrAnimation = new Shared<Animation>(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<Sprite>& shrSprite = pxySprite->getShared<Sprite>();
+ (*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<Animator>* shrAniamtor = new Shared<Animator>(new Animator(), Jin_Lua_Animator);
+ if (args >= 1)
+ {
+ Proxy* pxyAnimation = (Proxy*)luax_checktype(L, 1, Jin_Lua_Animation);
+ Shared<Animation>& shrAnimtion = pxyAnimation->getShared<Animation>();
+ (*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 },