You don't have to do that. You can just use the native texture resolution that you have and then choose the power of 2 above that if it doesn't fit. Use Texture:SetTexCoord(...) to crop the texture in-game instead. If you haven't noticed, a lot of Blizzard textures are comprised of multiple small textures mashed together in one big file. They then use texture coordinates to crop out individual parts.
Calculating the fractions on texture coordinates is a fairly simple formula:
Texture:SetTexCoord(left, right, top, bottom) - left - Left (or minX) edge of the scaled/cropped image, as a fraction of the image's width from the left (number)
- right - Right (or maxX) edge of the scaled/cropped image, as a fraction of the image's width from the left (number)
- top - Top (or minY) edge of the scaled/cropped image, as a fraction of the image's height from the top (number)
- bottom - Bottom (or maxY) edge of the scaled/cropped image, as a fraction of the image's height from the top (number)
|
Lua Code:
Texture:SetTexCoord(pxLeftFromLeftEdge / texWidth, pxRightFromLeftEdge / texWidth, pxTopFromTopEdge / texHeight, pxBottomFromTopEdge / texheight)
As an example, you can do this:
Lua Code:
-- Default
Texture:SetTexCoord(0, 1, 0, 1)
-- Horizontal flip
Texture:SetTexCoord(1, 0, 0, 1)
-- Vertical flip
Texture:SetTexCoord(0, 1, 1, 0)
-- Crop 25% from the left side
Texture:SetTexCoord(0.25, 1, 0, 1)
-- Crop 25% from the right side
Texture:SetTexCoord(0, 0.75, 0, 1)
Here's how you can use photoshop's reference point (the 9-piece grid) to find the coordinates with relative ease:
There's also a longer version of Texture:SetTexCoord(...) that allows you to specify all four corners of the texture. You can think of that approach as holding up a towel and grabbing at different points on it to let the unwanted part fold away, but that's not necessary if you're not cropping + rotating at the same time.