Sprite Flipping & Texture Offsets

This commit is contained in:
Isuru Samarathunga
2025-11-02 16:05:43 +05:30
parent 7d69518bdc
commit e4cd9abe52
3 changed files with 16 additions and 5 deletions

View File

@ -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<Resource_SpriteSheet*>(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

View File

@ -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