What does the number represent?
System.out.println();
//the method could be like
public void say(String words, int number)
{
System.out.println(words, number);
}/**
* Breaks up a sprite sheet.
*
* @param spriteSheet The sprite sheet to use.
* @param width The width that the resulting sprites should be.
* @param height The height that the resulting sprites should be.
* @return A 2D array of sprite images.
*/
public static GreenfootImage[][] parseSpriteSheet(GreenfootImage spriteSheet, int width, int height) {
int numCols = spriteSheet.getWidth() / width;
int numRows = spriteSheet.getHeight() / height;
GreenfootImage[][] sprites = new GreenfootImage[numCols][numRows];
for(int x = 0; x < numCols; x++)
for(int y = 0; y < numRows; y++) {
GreenfootImage img = new GreenfootImage(width, height);
// There may be a better way of doing this,
// but I do so little stuff in Java that I
// can't remember if there's a function to
// create a GreenfootImage from a section
// of another one. Hence, for now, I just
// copy it across pixel by pixel.
for(int x2 = 0; x2 < width; x2++)
for(int y2 = 0; y2 < height; y2++) {
img.setColorAt(
x2,
y2,
spriteSheet.getColorAt(
x*width + x2,
y*height + y2));
}
sprites[x][y] = img;
}
return sprites;
}public static GreenfootImage[] flattenArray(GreenfootImage[][] array) {
int width = array.length;
int height = array[0].length;
GreenfootImage[] flatArray = new GreenfootImage[width * height];
for(int x = 0; x < width; x++)
for(int y = 0; y < height; y++) {
flatArray[x + y*width] = array[x][y];
}
return flatArray;
}
public GreenfootImage[][] parseSpriteSheet(GreenfootImage spriteSheet, int imagesAcross, int imagesDown)
{
GreenfootImages[][] images = new GreenfootImages[imagesDown][imagesAcross];
int wide = spriteSheet.getWidth()/imagesAcross;
int high = spriteSheet.getHeight()/imagesDown;
for (int j=0; j<imagesDown; j++) for (int k=0; k<imagesAcross; k++)
{
images[j][k] = new GreenfootImage(wide, high);
images[j][k].drawImage(spriteSheet, -k*wide, -j*high);
}
return images;
}