Search code examples
javajbox2d

Work with images in Jbox2d (java)


I am trying to make the image move rather than a geometric shape in jbox2d. I dont see the image .

BodyDef bodyDef =new BodyDef();
        bodyDef.position.set(100,100);
        bodyDef.type=BodyType.DYNAMIC;
        //texture=TextureLoader.getTexture("PNG",ResourceLoader.getResourceAsStream("resources/small.png"));
        BufferedImage img = null;
        try {
            img = ImageIO.read(new File("resources/small.png"));
        } catch (IOException e) {
        }
        bodyDef.userData=img;

Solution

  • JBox2D is based on the Box2D engine, which is a physics engine, nothing relative to something visual. You have to draw the image yourself in the main loop of the program, a method often called render().