|
import java.util.ArrayList;
public class TexturePuzzle
{
private ArrayList<TextureSize> listSize;
public TexturePuzzle(TextureSize textureSize)
{
listSize = new ArrayList<TextureSize>();
listSize.add(textureSize);
}
public int getNumTextures()
{
return listSize.size();
}
public int getHeight(int index)
{
return listSize.get(index).getHeight();
}
public int getWidth(int index)
{
return listSize.get(index).getWidth();
}
public int getNumPixels()
{
int numPixels = 0;
for (int n = 0; n < listSize.size(); n++)
{
numPixels += listSize.get(n).getNumPixels();
}
return numPixels;
}
public void getNextSizeFits(int pixels, int maxWidth, int maxHeight)
{
do
{
if (pixels <= getNumPixels() &&
maxWidth <= getWidth(0) &&
maxHeight <= getHeight(0))
{
break;
}
incTextureSize();
} while(true);
}
public void incTextureSize()
{
TextureSize lastTextureSize = listSize.get(listSize.size()-1);
if (lastTextureSize.isMaxSize())
listSize.add(lastTextureSize.clone());
else
lastTextureSize.incTextureSize();
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
After working in the software industry for many years, I've started my own
games company that specialises in strategy games for mobile platforms.