0

So, I am trying to make a program in Java that opens a JFrame window and displays images. these images are part of a Tile map/Sprite sheet.

g2.drawImage(image, screenX, screenY, gp.tileSize, gp.tileSize, null);

image is the whole image and ScreenX/Y is the location, and the tileSize is the size of the image - this is displaying the whole image, how would i display at the same size but only part of the image. If this is unclear please tell me so.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Poseidon
  • 3
  • 4
  • 3
    [`BufferedImage#getSubImage`](https://docs.oracle.com/en/java/javase/16/docs/api/java.desktop/java/awt/image/BufferedImage.html#getSubimage(int,int,int,int)) – MadProgrammer May 26 '22 at 01:19
  • For [example](https://stackoverflow.com/questions/23236054/drawing-an-assembled-image-to-the-jpanel/23237136#23237136); [example](https://stackoverflow.com/questions/27163399/how-can-i-draw-an-image-part-by-part/27163506#27163506); [example](https://stackoverflow.com/questions/12101520/java-graphics-drawimage-scaling-issue/12102015#12102015); [example](https://stackoverflow.com/questions/35472233/load-a-sprites-image-in-java/35472418#35472418); [example](https://stackoverflow.com/questions/54393447/make-animation-more-smoother/54396190#54396190) – MadProgrammer May 26 '22 at 01:25
  • 1
    1) `g2.drawImage(image, .., null);` should instead be `g2.drawImage(image, .., this);`. 2) Custom painting should be done in a `JPanel` added to the `JFrame`. – Andrew Thompson May 26 '22 at 05:58

0 Answers0