I recently started making simple games using Java2D, and have come up with a couple of questions about creating/handling Images. There’s a lot of good advice about this topic in these forums, but it seems to be spread out and not in one place (and a lot of it is relatively old - what’s accelerated and what’s not seems to change from one JRE release to the next).
- If your game only ever runs in a window (no FSEM), and uses a Canvas to render on, is there any difference between:
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(w, h)
and
canvas.getGraphicsConfiguration().createCompatibleImage(w, h)
I’d naively imagine these values would be the same. And are things any different in FSEM?
- In games with lots of sprites, I find myself loading a single image that I use as a “sprite sheet” containing all frames of animation for a sprite(s). The actual sprite instances themselves will contain an (x,y) coordinate into the sprite sheet for each frame, and to render they call one of the Graphics.drawImage() overloads that take a subrectangle into the image to draw. The question is: how does this affect performance, if at all? Is it really worth it to break a “sprite sheet” apart into several smaller images, and draw the proper one at the right time? It certainly seems simpler not to break it apart if possible.