简体   繁体   中英

Graphics2D multi-composite of an isometric tile map

I'm working on a game which uses isometric tile-based maps for planetary surfaces ( example ). Each of the tile cell is a small BufferedImage element. Day and night cicles are implemented by modifying the pixels of these images (darkening and blue shifting), then a window-light map (another static BufferedImage) is rendered over each building. The proper Z-order is kept by going in top-right-bottom-left order and only strips of the tiles are drawn. Unfortunately, this approach practically destroys the acceleration of the images and the rendering becomes very slow if the day-night transition happens on very fast game speed. The current solution is to cache a number of shades for each tile at the cost of huge memory increase.

Can the Java composition modes of Graphics2D used for this purpose, eg, draw the normal colored tile, draw a darkened surface over it, then apply the light-map? How can I ensure that only the pixels of the normal tile are affected by the recoloring?

The fastest approach to me seems something like the following:

  1. Render the view with plain images to the target buffer
  2. Render the view with lightmap images on a second BufferedImage
  3. Draw the second BufferedImage on the target buffer using a custom CompositeContext

The custom CompositeContext would first apply the darkening + blue shifting, and then multiply by the lightmap value.

Also look into the use of VolatileImage (see this article for example) to leverage hardware acceleration. Furthermore, you can consider using LWJGL (a complete game dev library) or JOGL (Java OpenGL bindings), again to leverage hardware acceleration. If you've never done any 3D programming it may seem daunting or overkill, but it's really quite elegant and straightforward for 2D graphics as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM