Tile/Map-Based Game Techniques: Handling Terrain
Transitions
by David Michael
This article is another in my series of Tile/Map-based Game Techniques. In
this article I discuss a method for handling terrain transitions on your main
map display.
First off, by "terrain" I am referring to the background or base layer of
graphics for the map display. Terrain might refer to normal terrain types, such
as grasslands or forests, but it is not limited to this. In a science-fiction
game, for instance, the terrain could be bare metal or even the landscape
features of another planet.
The Problem
The problem of terrain transitioning grows out of the need for a single type
of terrain to be able to mesh with itself and still look good when placed next
to another terrain. A forest tile should fit together with other forest tiles so
that the forest proceeds seamlessly from one map cell to the next. But what
happens when the forest tile is placed next to another type of terrain, such as
mountains or grassland? Without some form "transitioning" the map looks very
blocky and artificial.
Figure 1: Terrain Without Transitions
One solution to the problem is to create specialized transition tiles that
"blend" sections of each terrain into a single tile. However, the need for all
terrains to transition into any other means that the number of specialized tiles
escalates quickly. It may not be obvious at first glance, but the number of
transitions required even between just 2 terrain types is quite large. On a
square grid, there are 8 possible points of transition: one for each side and
one for each corner. Even the simple forest-to-grassland transition would
require 256 transitions, and this would have to be done for each terrain
transition combination. If you have 9 or 10 terrain types, the amount of
graphics this approach would require is unworkable.
This can be refined some by using transitions with a transparent element,
allowing for more variety with fewer tiles. The forest transitions would then be
able to overlap any terrain. But 256 transition variations for each terrain type
still seems pretty excessive.
So how do you trim down the number of required transition graphics to a
number that is more manageable? This is how we did it.
Our Solution
The first part of our solution was to assign a "precedence" to the various
terrain types. By precedence, I mean that when two different terrain types meet,
one of them invariably "overlaps" the other. In the example of forest meeting
grassland, if forest has a higher precedence (and it should) then it will always
overlap the grassland.
In Artifact, we used the following terrain precedence (listed highest to
lowest): jungle, forest, mountain, hill, swamp, deserts, grassland, water (open
water or river). Please note that this precedence does not reflect the relative
elevations of the terrain but is instead based on which terrains looks best when
overlapping other terrains.
Figure 2: Artifact Terrain Precedence
The next step was to reduce the number of terrain transition variations from
256. This number can be cut drastically by separating the "edge" transitions and
the "corner" transitions. As it was pointed out above, a single terrain cell has
8 points of transition: one for each side and one for each corner. Thus, there
are only 16 possible edge transitions, and 16 possible corner transitions. By
using combinations of edge and corner transitions you can create all of the
necessary 256 variations with only 32 total tiles. This is a huge reduction in
graphics required.
The template we used followed a binary format. For the edges, west was
considered "bit 0", north was "bit 1", and east and south were "bit 2" and "bit
3", respectively. Similarly for the corners, the northwest corner was "bit 0",
the northeast corner "bit 1", and so on. How we arranged the actual terrain
transition graphics is demonstrated in Figure 3. If you think of the covered
edges as 1 and the non-covered edges as 0, you can see that the columns proceed
in normal binary manner: 0000, 0001, 0010, 0011, 0100, and so on.
Figure 3: Terrain Transition Template
Figure 4 shows how this was applied to create the grassland transitions in
Artifact.
Figure 4: Artifact Grassland Transitions
With this method drawing the map is now a 2-step process. For each map cell,
the base terrain must be drawn, and then any transitions that overlay it in
reverse order of precedence (lowest precedence drawn first). However, the
reduction in graphics required more than makes up for the additional work. Also,
since the transition graphics are mostly transparent, the actual "work" involved
is less than it might seem.
Using the precedence established earlier, and the bit assignments for the
edges and corners, calculating which transitions you need in a particular map
cell is relatively straightforward. Essentially, for each map cell, you check
all adjacency possibilities for terrain types that overlap the terrain of the
cell. The transition information for a single terrain type need only use 8-bits
of data (4 bits for the edges and 4 bits for the corners) which fits
conveniently into a single byte. Thus, the total terrain transition information
for Artifact's 9 terrain types requires only 9 bytes per map cell.
You can pre-calculate the transition information and store it with the map,
or you can calculate it "on the fly" at runtime. For rendering Artifact's map
display, I calculate the transitions for the visible portion of the map only.
This reduces the amount of storage required since only a small portion of the
map is visible at one time.
A quick example: To calculate the transitions needed for a hill terrain, you
need only consider any adjacent jungles, forests, and mountains, since those are
the only terrain types that have a higher precedence. Figure 5 demonstrates the
overlapping of transitions on the base terrain graphics, with a hill as the
center terrain.
Figure 5: Artifact Terrains, Before and
After
Conclusion
With a bit of preparation in the graphics and a few tricks during the
rendering, you can achieve professional-looking terrain transitions in your
game. While drawing the map becomes a bit more complicated, the reduction in
graphics required and the flexibility of the system more than make up for
that.
David Michael is co-owner of Samu Games and has produced several online
games, including Artifact and Paintball NET.
Copyright ?1999 by David Michael. All Rights
Reserved.
All Artwork Copyright ?1999 by Samu Games. All Rights
Reserved.
Discuss
this article in the forums
Date this article was posted to GameDev.net:
2/23/2000
(Note that this date does not necessarily correspond to the
date the article was written)
- 大小: 8.2 KB
- 大小: 5.7 KB
- 大小: 4.6 KB
- 大小: 2.7 KB
- 大小: 8.2 KB
分享到:
相关推荐
在本课程中,“Unity 2D Toolkit RPG地图块拼接”着重讲解了如何利用Unity引擎以及2D Toolkit插件来创建角色扮演游戏(RPG)的2D地图。这个技术是游戏开发中的关键部分,尤其对于那些希望打造像素艺术风格或者传统2D...
unity2d 根据像素图生成地图.
在这个项目中,我们关注的是如何使用VC++编程语言来实现Kriging算法,以生成2D和3D地图的等高线。 首先,我们要理解Kriging的基本概念。Kriging是由南非矿业工程师Danie G. Krige发展起来的一种估计方法,它通过...
在Java编程语言中,我们可以利用线缓冲区生成算法来有效地处理大量的线条绘制任务,尤其是在2D图形渲染中。本工程提供的代码示例是基于Java实现的线缓冲区生成算法,特别是采用了平行双线法,这使得程序能够在内存中...
在游戏开发领域,2D地图的设计与实现是一个重要的环节,特别是在一些复古风格或者像素艺术类游戏中。本主题将深入探讨2D 45度斜角地图的原理,这对于那些对游戏编程感兴趣,尤其是使用ActionScript 3.0(AS3.0)进行...
《Tiled-2D地图编辑器与Unity集成详解》 在游戏开发中,2D地图编辑器是构建游戏世界不可或缺的工具,其中Tiled是一款广受欢迎的开源2D地图编辑器。本文将深入探讨Tiled的功能特性,以及如何与Unity引擎进行无缝集成...
- **地形生成**:通过算法自动生成随机或基于规则的地形。 - **光照和阴影**:模拟光照效果,增加地图的真实感。 - **网络协作**:多人同时在线编辑同一地图,提高团队工作效率。 - **自定义脚本**:高级用户...
在本文中,我们将深入探讨如何使用ECharts,一个流行的JavaScript数据可视化库,来实现2D地图的3D阴影效果,特别是在展示山东省地图时的应用。ECharts 提供了丰富的图表类型和自定义选项,使得开发者能够创建出具有...
总之,这个2D/3D图像配准算法实验代码是学习和研究图像配准的一个实用工具,涵盖了尺度不变性特征检测、Harris角点检测以及Matlab实现的图像配准算法。通过实际操作和调试这些代码,不仅可以深化理论知识,还能提高...
Go-dngn是一个专为游戏设计的Golang库,致力于实现高效且灵活的随机地图生成算法。这个库提供了丰富的功能,使得开发者可以快速构建各种类型的游戏世界,包括地下城、迷宫、岛屿等。 首先,我们要理解Go-dngn的核心...
lsometric Road Blocks插件 2D 45度地图道路区块 这是一个可下载的游戏2D资源包可开发经营类游戏或者益智游戏 2D Pixel Art - Isometric Road Blocks - Free Sprites的插件包含以下内容: - 60种游戏元素 - 格式:...
- **地形生成**:通过算法自动生成复杂地形,如Perlin噪声用于生成自然景观。 了解并掌握2D基础地图编辑器的知识,对于游戏开发、地理信息处理以及创意设计等领域的专业人士至关重要。通过不断实践和探索,你可以...
总的来说,使用MFC开发2D地图编辑器是一项涉及图形用户界面设计、数据结构与算法、文件I/O、事件处理等多个方面的综合任务。理解并熟练运用MFC类库,结合良好的编程习惯和设计模式,可以帮助我们构建高效、易用的2D...
2D转3D算法是一种计算机图形学技术,其主要目标是将二维图像转换为具有立体感的三维图像。这项技术广泛应用于电影、游戏、虚拟现实等领域,为用户提供更丰富的视觉体验。2D转3D算法涉及到多个关键步骤和技术,下面...
这个是我个人自己写的Unity 2D环境中的寻路, 分别有两个文件夹,AIPath 是正面2D 环境,45AIPath 是斜45度角(2.5D)环境,本资源包含了一份PDF繁体中文教学文件,而在最后我也提出了一些问题,望高手解答。此算法也是...
在易语言2D地图合成器源码中,我们可能会发现一些关键功能模块,如地图种子生成器(用于确保每次生成的地图都是独特的)、地形图层管理(用于处理不同类型的地形)、对象分布算法(用于随机放置游戏中的物品和角色)...
c# winform 2d 地图编辑器。用于各种应用
首先,我们来探讨直线段生成算法。在2D坐标系中,直线段由两个端点定义,即(x1, y1)和(x2, y2)。最简单的直线生成算法是Bresenham算法,它是一种离散化算法,用于高效地在像素级别上绘制直线。该算法的核心思想是...
包含用于 2D 不规则打包的算法和算法的简单教程 算法 Bottom-Left-Fill.py:嵌套问题的 2-exchange 启发式 2002 genetic_algorithm.py:嵌套问题的 2 交换启发式算法 2002 nfp_test.py:针对不规则切削问题的完整...