Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Creating sprites

Vrekt edited this page Jul 19, 2018 · 1 revision

Here you will learn how to use the SpriteManager to load your sprites and create custom tiles.

The SpriteManager

You can get the instance to the SpriteManage by using your 1GameManager` instance.

SpriteManager manager = myGameManager.getSpriteManager();

Now you can load your custom sprite sheet and add it to the SpriteManager.

String path = "C:\Path\To\SpriteSheet.png";
BufferedImage sheet = manager.loadImage(path);

// lets add it now!
manager.addImage("CharacterSprites", sheet);

Once you add the image you can get it anytime by using SpriteManager#getImage(String name);

Now that you have your sprite-sheet loaded and ready you can now get sprites from it.

As an example, my sprite-sheet contains a 4x4 array of an NPC character. Each sprite represents a different walking frame of that NPC.

So lets say the top row contains the frames for walking left, you can get all those frames in one method call.

BufferedImage[] frames = manager.getMultipleImages(image, x: 0, y: 0, xModifier: 32, yModifier: 32, width: 16, height: 16, direction: Directional.RIGHT, totalImages: 4);

This method will return an array of images from the provided image.

x, y: this is where to start on the base image, for this example I started at 0, 0.

xModifier, yModifier: some sprite-sheets include spacing between sprites, that is what this field is for.

width, height: the dimensions of the image you're getting, for this example my sprite was 16x16.

direction: the direction to go to, I wanted to get the whole top row so I started at 0, 0 and went right.

totalImages: this is how many images you wish to get, each row had 4 sprites.

You can also create multiple tiles from multiple images. The method is as follows,

Tile[] tiles = manager.createTilesFromMultipleImages(image, x: 0, y: 0, xModifier: 32, yModifier: 32, width: 16, height: 16, direction: Directional.LEFT, totalImages: 4, properties: new Tile.TileProperties[] {new Tile.TileProperties(true)}, tileIds: idArray);

x, y, xModifier, yModifier, width, height, direction, totalImages: see above.

properties: These are the custom properties to use for each tile. If the length of the array is 1, then it uses that property for all tiles.

tileIds: these are the Ids to use for your tiles. If you specify the array as 'null' Stellar will create the Ids for you.

Clone this wiki locally