take a sprite image from a "sprite sheet"

Hi guys, I’ve a question:

I was looking this link: http://sprites.fireball20xl.com/nintendo/mario/smw2/smw2badguys.gif

it’s possible to acquire directly my sprites images from a sprite sheet like that?
If yes, how I can do? I’ve to specify the (x,y) coordinates and the width,height of the single image?

What I normally do is the following:

load the sprite sheet

for each sprite in the sprite sheet
   create a new image (im)
   draw the sprite in the sprite sheet to the new image

Yes, you would have to specify the (x,y) coordinates and width and height in the draw image method.

The only pitfall here is that transparent pixels won’t be copied as transparent pixels (instead, you’ll wind up with black because that’s what the new image is initialized to). Typically, I have the sprite sheet use a “special” color for transparency and then convert it to alpha channel transparency AFTER copying the images.

A better alternative would be just to extract the pixel data from the sprite sheet’s image (as an int[][]) and then create the new image from the int[][].

I was just going through the Shared Code forum and this caught my eye and then I saw your problem which this code would help you out I’m sure.

http://www.java-gaming.org/forums/index.php?topic=14708.0

Hope that helps.