My Little Project

infamoustrey

Junior Member
Apr 15, 2012
20
0
66
Hello! I am making a video game with some graphics off the net to test my mettle!

So my mettle has been tested and I am trying to animate a sprite using a sprite sheet. And my problem is trying to call the subImages.

Code:
public class Paladin {


	BufferedImage AA = null; {
		try {
		    AA = ImageIO.read(new File("Censored Location"));
		} catch (IOException e) {
		}
	}
	
	final int width = 96; 
	final int height = 95; 
	final int rows = 7; 
	final int cols = 9; 
	public BufferedImage[] sprites = new BufferedImage[rows * cols]; { 

		for (int i = 0; i < rows; i++) 
		{ 
		    for (int j = 0; j < cols; j++) 
		    { 
		        sprites[(i * cols) + j] = AA.getSubimage( 
		            i * width, 
		            j * height, 
		            width, 
		            height 
		        ); 
		    } 
		} 
	}
	
}

So My Question is how to I call each subImage.
Playful Banter is allowed :sneaky:
This is in java! For the small of wit.
 

BrightCandle

Diamond Member
Mar 15, 2007
4,762
0
76
You mean render the actual images to the screen?

If so you need to read the Swing tutorial as you'll need to create yourself a JFrame and then put a JComponent into that frame which you extend and then override the paint(Graphics g) method and you'll find that g.drawImage will do a good part of what you want. You then need to work out how to run a schedule to make it render frequently and choose the right image.

There was actually a book for Java quite a while ago http://www.brackeen.com/javagamebook/ that contained details of how to do sprite animation and such but you certainly don't need it to get started.