1

In Swing, if I were to use the Graphics2D drawImage method to draw an image at coordinates so that it would not be seen at all in the visible panel e.g 100 by 100 panel, drawing a 100 by 100 image at -200, -200, Would this affect the rendering time just as much as if it were within the range of the panel and this painted to screen?

Or would it be better to have copious amounts of statements to check whether something is within the range of the panel and if not, don't draw it?

This is for a game with lots of images moving around the panel coordinates and some may go leave the range of the panel.

Cheers

ultrablue
  • 65
  • 6

1 Answers1

1

The Graphics context specifies that "All rendering operations modify only pixels which lie within the area bounded by the current clip," so no additional checks are typically required. See Painting in AWT and Swing for additional details.

As a concrete example, MapPanel continues to render vehicles that have moved off the grid as the simulation evolves. Click a stray cab's Reset button to bring it back into view.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045