Search code examples
java-mespritemidplcdui

How to get the size of sprite in a sprite "Sheet"?


my problem is getting the Sprite in a Sprite "Sheet".

    public class Blocks extends Sprite{
        public Blocks() throws IOException
            {
                super(Image.createImage("/blockSprite.png"),20,30);
            }
    }        

"the blockSprite.png contains images of Sprites, many sprites in 1 image"

The problem here is using this line of code, how I am supposed to get the Sprite size/dimension in the image?

Sprite Sheet:
Width - 162
Height - 280

I want to know the width/height of the sprites in the sheet? and how to determine the width/height of the sprites in a Sprite Sheet?


Solution

  • You do know how many sprites are there in each row and column right? then just divide the width with how many sprites are there in a column and divide the height with how many sprites are there in a row.

    (I may get the column and row wrong, I'm not native English, but you should just switch the row/column if the first try didn't work out)