简体   繁体   English

等轴测图的Graphics2D多重复合

[英]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. 每个tile单元都是一个小的BufferedImage元素。 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. 通过修改这些图像的像素(变暗和蓝移)来实现白天和夜晚的冰柱,然后在每座建筑物上渲染一个窗口光照图(另一个静态BufferedImage)。 The proper Z-order is kept by going in top-right-bottom-left order and only strips of the tiles are drawn. 通过按右上-左下的顺序保持适当的Z顺序,并且仅绘制图块条。 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? Graphics2D的Java 合成模式是否可以用于此目的,例如绘制正常的彩色图块,在其上绘制变暗的表面,然后应用光照贴图? 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 在第二个BufferedImage上使用光照贴图图像渲染视图
  3. Draw the second BufferedImage on the target buffer using a custom CompositeContext 使用自定义CompositeContext在目标缓冲区上绘制第二个BufferedImage

The custom CompositeContext would first apply the darkening + blue shifting, and then multiply by the lightmap value. 自定义CompositeContext将首先应用变暗+蓝色平移,然后乘以光照贴图值。

Also look into the use of VolatileImage (see this article for example) to leverage hardware acceleration. 还要研究VolatileImage的使用(例如,请参见本文 )以利用硬件加速。 Furthermore, you can consider using LWJGL (a complete game dev library) or JOGL (Java OpenGL bindings), again to leverage hardware acceleration. 此外,您可以考虑再次使用LWJGL (完整的游戏开发库)或JOGL (Java OpenGL绑定)来利用硬件加速。 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. 如果您从未进行过任何3D编程,这似乎令人望而生畏,但对于2D图形来说,它确实非常优雅和简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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