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

Report as inappropriate.

GregorSmith presents ...


Greenfoot Sprite Sheet

(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.

## Source

## Requirements
Tested on Greenfoot 3.1.0. All sprites on a sheet must be spaced by the same amount.

## Usage
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.
spriteSheet.resizeAll(50, 100);
// 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 (

Animation walkAnimation = new Animation();
.forEach(sprite -> walkAnimation.addFrame(sprite, 100));

## License

2181 views / 13 in the last 7 days

Tags: demo with-source sprite spritesheet

open in greenfoot
Your browser does not support the canvas tag.

No Comments

Want to leave a comment? You must first log in.

Who likes this?

No votes yet.