I have this sprite sheet:
How can I read this image file to extract part of it to be used as a sprite ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If the sprites area read into a
BufferedImage, thegetSubimagemethod can be used to get a subimage of the sprite sheet.The
getSubimagemethod will take thex,y, and thewidthandheightof the desired subimage, so the desired sprite can be obtained. Since most of the sprites seem to be the same size, I would think most of them can be retrieved by a nestedforloop to iterate through the large image.For example, if the sprite image is loaded using the
ImageIOclass (such as thereadmethod), and each sprite is 10 pixels by 10 pixels in size, where are 5 rows by 5 columns of sprites, the sprites can be obtained by the following:The catch is, of course, the above code will only work if all the sprites are the same size, so there will need to be some adjustment performed in order to work for the given sprite sheet. (As the top right-hand corner seems to be different in size from the others.)