I have been looking around online to try to find a complete solution but as of now, I can only find pieces that don't fit together.
I'm looking for a program that can look at an image file, loop through the file and isolate the sprites and then save them. After that I need a way to re-access that sprite info so I can display it, but I would like to be able to display the tiles based on my own formulas. Think of a game like advanced wars with little terrain tiles. I want to be able to display those tiles semi-randomly, but within my own parameters.
I would also like to be able to load up a different image file that has the same size sprites as the above image but use these images for animations.
So I have 2 sprite sheets that have a bunch of 64x64 pixel sprites. One of the image files is all my terrain tiles. The other is my unit tiles. I want to be able to read in the sprites and display them any way I please.
I cant for the life of me figure out which way to do this. I've looked into Subimaging and drawImage, but I can't get them to store or redisplay information properly.
Thanks.
EDIT: So ive simplified my question for my own sake and for the sake of everyone else.
Why doesnt the following code work?
package animation;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class AnimTest
{
public static void main(String[] args)
{
AnimTest test = new AnimTest();
test.go();
}
public void go()
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MyDrawP drawP = new MyDrawP();
frame.getContentPane().add(drawP);
frame.setSize(500,500);
frame.setVisible(true);
}
}
class MyDrawP extends JPanel
{
public void drawSprite(Graphics g)
{
try {
BufferedImage bigImg = ImageIO.read(new File("C:/Users/scott/Desktop/Personal Work/Pixel Art/terrain.png"));
final int width = 64;
final int height = 64;
int x = 0;
int y = 0;
bigImg.getSubimage(x, y, width, height);
g.drawImage(bigImg, 5, 5, this);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sorry for the mess, i have NO idea how to format a code block properly.
Now with that code, i want the MyDrawP class to look at my file, grab a 64x64 piece of it starting at 0,0 and then save it and display it in the frame when its added to it. Im pretty sure the problem is that the method drawSprite is never called, but im not sure when to call it and im not sure if anything else is missing.
Again, why doesnt the above code work?
Thanks