diff --git a/Documentation/ScriptingAPI-Documentation.md b/Documentation/ScriptingAPI-Documentation.md index b95d30a05..1ca830ee3 100644 --- a/Documentation/ScriptingAPI-Documentation.md +++ b/Documentation/ScriptingAPI-Documentation.md @@ -223,10 +223,12 @@ Move texture continuously along the sprite. Animate sprite frame by frame. - [constructor]DrawRecAnim() - SetOnFrameChangeWait(float val) -- SetFrameCount(int val) - SetFrameRate(float val) -- GetFrameCount() : int result +- SetFrameCount(int val) +- SetHorizontalFrameCount(int val) - GetFrameRate() : float result +- GetFrameCount() : int result +- GetHorizontalFrameCount() : int result ### Texture Just holds texture information in VRAM. diff --git a/Tests/Tests.cpp b/Tests/Tests.cpp index 0d6b2e9ce..ffd05ff30 100644 --- a/Tests/Tests.cpp +++ b/Tests/Tests.cpp @@ -248,6 +248,7 @@ void TestsRenderer::RunFontTest() { static wiFont font; static wiFont font_upscaled; + int arial = wiFont::AddFontStyle(wiFont::GetFontPath() + "arial.ttf"); font.SetText("This is Arial, size 32 wiFont"); font_upscaled.SetText("This is Arial, size 14 wiFont, but upscaled to 32"); @@ -259,8 +260,8 @@ void TestsRenderer::RunFontTest() font_upscaled.params = font.params; font_upscaled.params.posY += font.textHeight() + 10; - font.style = wiFont::AddFontStyle(wiFont::GetFontPath() + "arial.ttf"); - font_upscaled.style = wiFont::AddFontStyle(wiFont::GetFontPath() + "arial.ttf"); + font.style = arial; + font_upscaled.style = arial; font_upscaled.params.size = 14; font_upscaled.params.scaling = 32.0f / 14.0f; @@ -319,14 +320,13 @@ void TestsRenderer::RunSpriteTest() { static wiSprite sprite("images/fire_001.png"); sprite.params.pos = XMFLOAT3(wiRenderer::GetDevice()->GetScreenWidth() * 0.5f, wiRenderer::GetDevice()->GetScreenHeight() * 0.5f, 0); - sprite.params.siz = XMFLOAT2(200, 200); - sprite.params.pivot = XMFLOAT2(0.5f, 0.5f); - sprite.params.enableDrawRect(XMFLOAT4(0, 0, 192, 192)); - sprite.params.sampleFlag = SAMPLEMODE_WRAP; - sprite.anim = wiSprite::Anim(); - sprite.anim.drawRectAnim.frameCount = 20; - sprite.anim.drawRectAnim.horizontalFrameCount = 5; - sprite.anim.drawRectAnim.frameRate = 40; - sprite.anim.repeatable = true; + sprite.params.siz = XMFLOAT2(200, 200); // size on screen + sprite.params.pivot = XMFLOAT2(0.5f, 0.5f); // center pivot + sprite.params.enableDrawRect(XMFLOAT4(0, 0, 192, 192)); // set the draw rect (texture cutout). This will also be the first frame of the animation + sprite.anim = wiSprite::Anim(); // reset animation state + sprite.anim.drawRectAnim.frameCount = 20; // set the total frame count of the animation + sprite.anim.drawRectAnim.horizontalFrameCount = 5; // this is a multiline spritesheet, so also set how many maximum frames there are in a line + sprite.anim.drawRectAnim.frameRate = 40; // animation frames per second + sprite.anim.repeatable = true; // looping addSprite(&sprite); } diff --git a/WickedEngine/SpriteAnim_BindLua.cpp b/WickedEngine/SpriteAnim_BindLua.cpp index 2b6a5d90b..e22cb7a6e 100644 --- a/WickedEngine/SpriteAnim_BindLua.cpp +++ b/WickedEngine/SpriteAnim_BindLua.cpp @@ -335,11 +335,13 @@ int MovingTexAnim_BindLua::GetSpeedY(lua_State *L) const char DrawRectAnim_BindLua::className[] = "DrawRecAnim"; Luna::FunctionType DrawRectAnim_BindLua::methods[] = { - lunamethod(DrawRectAnim_BindLua, SetFrameCount), lunamethod(DrawRectAnim_BindLua, SetFrameRate), + lunamethod(DrawRectAnim_BindLua, SetFrameCount), + lunamethod(DrawRectAnim_BindLua, SetHorizontalFrameCount), - lunamethod(DrawRectAnim_BindLua, GetFrameCount), lunamethod(DrawRectAnim_BindLua, GetFrameRate), + lunamethod(DrawRectAnim_BindLua, GetFrameCount), + lunamethod(DrawRectAnim_BindLua, GetHorizontalFrameCount), { NULL, NULL } }; Luna::PropertyType DrawRectAnim_BindLua::properties[] = { @@ -359,19 +361,6 @@ DrawRectAnim_BindLua::~DrawRectAnim_BindLua() { } -int DrawRectAnim_BindLua::SetFrameCount(lua_State* L) -{ - int argc = wiLua::SGetArgCount(L); - if (argc > 0) - { - anim.frameCount = wiLua::SGetInt(L, 1); - } - else - { - wiLua::SError(L, "SetFrameCount(int val) not enough arguments!"); - } - return 0; -} int DrawRectAnim_BindLua::SetFrameRate(lua_State* L) { int argc = wiLua::SGetArgCount(L); @@ -385,14 +374,45 @@ int DrawRectAnim_BindLua::SetFrameRate(lua_State* L) } return 0; } +int DrawRectAnim_BindLua::SetFrameCount(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + anim.frameCount = wiLua::SGetInt(L, 1); + } + else + { + wiLua::SError(L, "SetFrameCount(int val) not enough arguments!"); + } + return 0; +} +int DrawRectAnim_BindLua::SetHorizontalFrameCount(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + anim.horizontalFrameCount = wiLua::SGetInt(L, 1); + } + else + { + wiLua::SError(L, "SetHorizontalFrameCount(int val) not enough arguments!"); + } + return 0; +} +int DrawRectAnim_BindLua::GetFrameRate(lua_State* L) +{ + wiLua::SSetFloat(L, anim.frameRate); + return 1; +} int DrawRectAnim_BindLua::GetFrameCount(lua_State* L) { wiLua::SSetInt(L, anim.frameCount); return 1; } -int DrawRectAnim_BindLua::GetFrameRate(lua_State* L) +int DrawRectAnim_BindLua::GetHorizontalFrameCount(lua_State* L) { - wiLua::SSetFloat(L, anim.frameRate); + wiLua::SSetInt(L, anim.horizontalFrameCount); return 1; -} \ No newline at end of file +} diff --git a/WickedEngine/SpriteAnim_BindLua.h b/WickedEngine/SpriteAnim_BindLua.h index 3cb25aa27..378c95e03 100644 --- a/WickedEngine/SpriteAnim_BindLua.h +++ b/WickedEngine/SpriteAnim_BindLua.h @@ -75,10 +75,12 @@ public: DrawRectAnim_BindLua(lua_State *L); ~DrawRectAnim_BindLua(); - int SetFrameCount(lua_State* L); int SetFrameRate(lua_State* L); + int SetFrameCount(lua_State* L); + int SetHorizontalFrameCount(lua_State* L); - int GetFrameCount(lua_State* L); int GetFrameRate(lua_State* L); + int GetFrameCount(lua_State* L); + int GetHorizontalFrameCount(lua_State* L); }; diff --git a/WickedEngine/wiSprite.cpp b/WickedEngine/wiSprite.cpp index be93ae772..06726579c 100644 --- a/WickedEngine/wiSprite.cpp +++ b/WickedEngine/wiSprite.cpp @@ -122,42 +122,47 @@ void wiSprite::Update(float dt) params.texOffset.y += anim.movingTexAnim.speedY*dt; // Draw rect anim: - anim.drawRectAnim._elapsedTime += dt * anim.drawRectAnim.frameRate; - if (anim.drawRectAnim._elapsedTime >= 1.0f) + if (anim.drawRectAnim.frameCount > 0) { - // Reset timer: - anim.drawRectAnim._elapsedTime = 0; - - if (anim.drawRectAnim.horizontalFrameCount == 0) + anim.drawRectAnim._elapsedTime += dt * anim.drawRectAnim.frameRate; + if (anim.drawRectAnim._elapsedTime >= 1.0f) { - // If no horizontal frame count was specified, it means that all the frames are horizontal: - anim.drawRectAnim.horizontalFrameCount = anim.drawRectAnim.frameCount; - } + // Reset timer: + anim.drawRectAnim._elapsedTime = 0; - if (anim.drawRectAnim._currentFrame < anim.drawRectAnim.frameCount - 1) - { - // Advance frame counter if the animation is not finished: + if (anim.drawRectAnim.horizontalFrameCount == 0) + { + // If no horizontal frame count was specified, it means that all the frames are horizontal: + anim.drawRectAnim.horizontalFrameCount = anim.drawRectAnim.frameCount; + } + + // Advance frame counter: anim.drawRectAnim._currentFrame++; - // Step one frame horizontally: - params.drawRect.x += params.drawRect.z; - - if (anim.drawRectAnim._currentFrame > 0 && - anim.drawRectAnim._currentFrame % anim.drawRectAnim.horizontalFrameCount == 0) + if (anim.drawRectAnim._currentFrame < anim.drawRectAnim.frameCount) { - // if the animation is multiline, we reset horizontally and step downwards: - params.drawRect.x -= params.drawRect.z * anim.drawRectAnim.horizontalFrameCount; - params.drawRect.y += params.drawRect.w; - } - } - else if (anim.repeatable) - { - // restart if repeatable: - params.drawRect.x -= params.drawRect.z * (anim.drawRectAnim.horizontalFrameCount - 1); - params.drawRect.y -= params.drawRect.w * (anim.drawRectAnim.frameCount / anim.drawRectAnim.horizontalFrameCount - 1); - anim.drawRectAnim._currentFrame = 0; - } + // Step one frame horizontally if animation is still playing: + params.drawRect.x += params.drawRect.z; + if (anim.drawRectAnim._currentFrame > 0 && + anim.drawRectAnim._currentFrame % anim.drawRectAnim.horizontalFrameCount == 0) + { + // if the animation is multiline, we reset horizontally and step downwards: + params.drawRect.x -= params.drawRect.z * anim.drawRectAnim.horizontalFrameCount; + params.drawRect.y += params.drawRect.w; + } + } + else if (anim.repeatable) + { + // restart if repeatable: + const int rewind_X = (anim.drawRectAnim.frameCount - 1) % anim.drawRectAnim.horizontalFrameCount; + const int rewind_Y = (anim.drawRectAnim.frameCount - 1) / anim.drawRectAnim.horizontalFrameCount; + params.drawRect.x -= params.drawRect.z * rewind_X; + params.drawRect.y -= params.drawRect.w * rewind_Y; + anim.drawRectAnim._currentFrame = 0; + } + + } } } diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index a8fccc252..2c5d2adfc 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 23; // minor bug fixes, alterations, refactors, updates - const int revision = 4; + const int revision = 5; long GetVersion()