This site requires JavaScript, please enable it in your browser!
Greenfoot back
Upupzealot
Upupzealot wrote ...

2013/4/27

What's new in the coming version of Greenfoot?

1
2
3
4
MatheMagician MatheMagician

2013/4/28

#
What does the number represent?
JetLennit JetLennit

2013/4/28

#
Any number you would want (i personally use ints in those all the time)
bourne bourne

2013/4/28

#
JetLennit wrote...
I would also like a method for
System.out.println();
//the method could be like
public void say(String words, int number)
{
      System.out.println(words, number);
}
Are you simply wishing to not have to write out "System.out.prinln" ? This is not something Greenfoot needs to include. It's simple enough to write your own short hand method.
JetLennit JetLennit

2013/4/28

#
It was just my personal opinion..
bourne bourne

2013/4/28

#
I just giving you a straight answer. If they were to include something like this, it would probably look like: Greenfoot.println(String s)
JetLennit JetLennit

2013/4/28

#
true..... hadn't thought of that... and i apologize if i sounded too defensive
JetLennit JetLennit

2013/5/7

#
I would also like an animation thing where you select several images and it cycles through them and something that breaks up a sprite sheet
Duta Duta

2013/5/7

#
Here's something that breaks up a sprite sheet:
/**
 * 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;
}
If you just want a flat array (i.e. one-dimensional) rather than the 2D one returned by that method, you can either rewrite the method to use a flat array (this is the better option) or you could just use this method to convert it:
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;
}
The flat array's elements will be ordered like this:
danpost danpost

2013/5/7

#
An alternate way is:
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;
}
bourne bourne

2013/5/7

#
Would be nice to modify the template for new classes. Or just options to include Name/date in the header comment of new classes from like preferences. I say template because (in addition to backspacing then typing name/date etc.) I backspace a lot to clean up the default structure. (such as example method, unnecessary/prompting comments, padded white space found following brackets/parens etc.) In that it takes close to 8-10 seconds each time I create a new class. And I'm getting into a habit of disliking imports with '*'.
danpost danpost

2013/5/8

#
@bourne, you can modify the files used to create the default templates with any standard text editor (I prefer WordPad). I found my files at: Greenfoot\lib\english\greenfoot\templates
bourne bourne

2013/5/8

#
Oh. You on a pc? I tried looking (I'm on a mac. Went to show package contents - did a search and dug around). But didn't find anything.
danpost danpost

2013/5/8

#
I'm on a laptop, running Windows 7, using stick version of Greenfoot/BlueJ.
bourne bourne

2013/5/8

#
Never mind I think I found it. Was in a folder labeled Templates after all. Thanks for the help! Still might be nice for an automated date. But this almost as good! I must not have looked very hard, /Applications/Greenfoot 2.2.1/Greenfoot.app/Contents/Resources/Java/english/greenfoot/templates
bourne bourne

2013/5/8

#
Are there any date template variables that Greenfoot reading the template will substitute? Like $DATE, $MONTH, $YEAR ? I tried several guesses but no luck.
There are more replies on the next page.
1
2
3
4