diff --git a/Samples/RPG/Src/imp/cpp/Game.cpp b/Samples/RPG/Src/imp/cpp/Game.cpp index 09312a4..75f0c33 100644 --- a/Samples/RPG/Src/imp/cpp/Game.cpp +++ b/Samples/RPG/Src/imp/cpp/Game.cpp @@ -55,7 +55,7 @@ namespace ia::iae::rpg VOID OnUpdate(IN FLOAT32 deltaTime) { - IAEngine::DrawSprite(g_playerSpriteSheet, 0, 0, {100.0f, 100.0f}); + IAEngine::DrawSprite(g_playerSpriteSheet, 2, 0, {100.0f, 100.0f}, {1.0f, 1.0f}, 0.0f); } VOID OnResize(IN INT32 newWidth, IN INT32 newHeight) diff --git a/Src/IAEngine/imp/cpp/IAEngine.cpp b/Src/IAEngine/imp/cpp/IAEngine.cpp index 30dc5a3..d403d25 100644 --- a/Src/IAEngine/imp/cpp/IAEngine.cpp +++ b/Src/IAEngine/imp/cpp/IAEngine.cpp @@ -288,6 +288,6 @@ namespace ia::iae IN Vec2 scale, IN FLOAT32 rotation, IN BOOL flipH, IN BOOL flipV, IN Vec2 uvOffset) { const auto t = static_cast(g_resources[spriteSheet]); - Renderer::DrawDynamicSpriteTopLeft(t->Texture, animationIndex, frameIndex, position, scale, rotation, flipH, flipV, uvOffset); + Renderer::DrawDynamicSpriteTopLeft(t->Texture, frameIndex, animationIndex, position, scale, rotation, flipH, flipV, uvOffset); } } // namespace ia::iae \ No newline at end of file diff --git a/Src/IAEngine/imp/cpp/Renderer.cpp b/Src/IAEngine/imp/cpp/Renderer.cpp index 153f88c..22650a5 100644 --- a/Src/IAEngine/imp/cpp/Renderer.cpp +++ b/Src/IAEngine/imp/cpp/Renderer.cpp @@ -356,10 +356,21 @@ namespace ia::iae { const auto &d = g_texureData[texture]; const auto &t = g_activeTextureAtlasUVMap[texture]; - const auto pX = (tileIndexX * ((FLOAT32) d.TileWidth)) * g_activeTextureAtlasInverseSize.x; - const auto pY = (tileIndexY * ((FLOAT32) d.TileHeight)) * g_activeTextureAtlasInverseSize.y; - return Vec4(t.x + pX, t.y + pY, d.TileWidth * g_activeTextureAtlasInverseSize.x, + const auto pX = ((tileIndexX + uvOffset.x) * ((FLOAT32) d.TileWidth)) * g_activeTextureAtlasInverseSize.x; + const auto pY = ((tileIndexY + uvOffset.y) * ((FLOAT32) d.TileHeight)) * g_activeTextureAtlasInverseSize.y; + auto texCoords = Vec4(t.x + pX, t.y + pY, d.TileWidth * g_activeTextureAtlasInverseSize.x, d.TileHeight * g_activeTextureAtlasInverseSize.y); + if(flipH) + { + texCoords.x += texCoords.z; + texCoords.z *= -1; + } + if(flipV) + { + texCoords.y += texCoords.w; + texCoords.w *= -1; + } + return texCoords; } } // namespace ia::iae