3

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?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 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 Answers4

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.

Community
  • 1
  • 1
Zarkonnen
  • 22,200
  • 14
  • 65
  • 81
2

I recommend Java 2D.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
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
1

You might find the Slick2D framework useful - it's well designed for simple 2D games and includes tools for sound effects, input handling etc.

mikera
  • 105,238
  • 25
  • 256
  • 415