开发者

Drawing 2D graphics [closed]

开发者 https://www.devze.com 2023-04-12 11:35 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered开发者_StackOverflow社区 in its curr
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered开发者_StackOverflow社区 in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

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?


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.


I recommend Java 2D.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号