Report as inappropriate.
(Note: this scenario is just a dummy. I'm not sure if there's any way to upload a library or something to the Greenfoot site without making it into a scenario.)
Lazily loads GreenfootImages from a single large sprite sheet file instead of numerous individual files.
Tested on Greenfoot 3.1.0. All sprites on a sheet must be spaced by the same amount.
It's very simple:
// Load sprites from images/spritesheet.png, which has 3 rows and 4 columns.
SpriteSheet spriteSheet = new SpriteSheet("spritesheet.png", 3, 4);
// Resize if need be.
// Get individual sprites by their (x, y) coordinates
GreenfootImage sprite = spriteSheet.getSprite(0, 0);
GreenfootImage otherSprite = spriteSheet.getSprite(1, 2);
Integrates well with one of my other projects, Greenfoot Animation Controller (https://github.com/elcr/greenfoot-animation-controller):
Animation walkAnimation = new Animation();
.forEach(sprite -> walkAnimation.addFrame(sprite, 100));
GNU GPL V3
Want to leave a comment? You must first log in.
No votes yet.