I would like to make a simple game in Java that has already been designed. I just need a way to draw sprites, etc. It doesn't have to be anything complicated. What would be the first choice you'd recommend for this?
Asked
Active
Viewed 6,058 times
3
-
are we talking Swing here? I deducted so from a (erroneous) answer, but actually don't know from the question – kleopatra Oct 13 '11 at 21:23
-
If you are new to games I can recommend you this tutorial: http://www.youtube.com/playlist?list=PLsc8wGybU2IZui4lAad9F8lFjdkn2ZdWD Not much about the final product but will give you good idea how to organize the base code structure and what you can do with just default libraries. – d.raev Nov 16 '12 at 14:59
4 Answers
4
I would heavily suggest you go with a sprite system built on top of OpenGL, like Slick2D or libgdx. Java 2D graphics drawing is too slow to be used for sprite-based games without major headaches. I speak from bitter experience.
1
extending a JPanel is a good start:
public class SpriteDrawer extends JPanel
{
public SpriteDrawer()
{
try
{
sprite = ImageIO.read(new File("..//images//sprite.PNG"));
}catch(Exception e){e.printStackTrace();}
frame = new JFrame("Sprite Drawer");
frame.add(this);
frame.setSize(400,400);
frame.setVisible(true);
}
public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
g2.drawImage(0,0,400,400);
}
private JFrame frame;
private Image sprite;
}
this is a good example of overriding the paint method in JPanel. I hope this is what you were looking for, if not let me know and i can help you out.

gsfd
- 1,070
- 2
- 12
- 17
-
no, it's not a good example: in Swing, the method to override for custom painting is paintComponent(...) – kleopatra Oct 13 '11 at 07:03
-
-
-
i can program however i want and i do it that way and it works fine. I never have any problems. – gsfd Oct 13 '11 at 21:17
-
yeah, sure, you are free to do whatever mistakes you insist to doing ;) – kleopatra Oct 13 '11 at 21:20
-
i hope that attitude gets you as far in life as you deserve to go. nowhere. =) – gsfd Oct 13 '11 at 21:21
-
the expert in "little bit about C and Assembler" speaking about jave2d. You learn. End of story. – kleopatra Oct 13 '11 at 21:27