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

Report as inappropriate.

GregorSmith
GregorSmith presents ...

2017/5/8

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
https://github.com/elcr/greenfoot-spritesheet

## 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 (https://github.com/elcr/greenfoot-animation-controller):

Animation walkAnimation = new Animation();
walkAnimation.setLooping(true);
spriteSheet.getRow(0)
.forEach(sprite -> walkAnimation.addFrame(sprite, 100));

## License
GNU GPL V3

1796 views / 7 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.