游戏邦在:
杂志专栏:
gamerboom.com订阅到鲜果订阅到抓虾google reader订阅到有道订阅到QQ邮箱订阅到帮看

分享两种类型的单向地形动画制作方法

作者:Dan FitzGerald

在《Dog Sled Saga》中,地形只向左移动,从“镜头”看,它是由几层远近不同的地形图层组成的。有些铺瓷砖,所以我们不妨称组成地形图层的图像块为“瓷砖”。首先,每一层只有一张地形瓷砖,可以用相当简单的动画程序做出向左移动的效果。但是当我们开始制作长度各异的新瓷砖时,重写就是必要的。

dogs led saga(from dogsledsaga.com)

dogs led saga(from dogsledsaga.com)

一开始,当地形图层是由外观一致、相同宽度的瓷砖组成时,每一层的宽度都比屏幕宽度还多出一块瓷砖。

各层以相同的速度向左滑出,一旦移出一块瓷砖的宽度(即最左的一块瓷砖完全离开屏幕),这块瓷砖就会返回最右边。地图的表观运动是无缝的,并没有产生多余的瓷砖。

tile-block-shift(from gamasutra)

tile-block-shift(from gamasutra)

在上图中,我用蓝色边框的长方形表示地形图,再加上简单的动画,这个系统就差不多完成了。然而,这是一个点位符系统。我们希望做出宽度任意的随机地图,即可以看到诸如建筑、草地、雪堆、高山等等。如果地形图层只是一组瓷砖大块,就无法满足我们的要求。

我写了一个新系统。当瓷砖向左离开屏幕、需要添加新瓷砖时,这个系统就会将左边的瓷砖切下来放到右边。经常出现的瓷砖是从基于Loanshark的对象库(游戏邦注:这是一个用Action Script 3.0编写的对象库)中抽出来的(它们被移除后可以重复利用,所以不必每次都制作新对象),而特殊的瓷砖则根据需要产生。

tile-cutting-and-adding(from gamasutra)

tile-cutting-and-adding(from gamasutra)

上面的动画中,只有一个大小不规则的瓷砖,但根据相同的方法你可以添加更多特殊的瓷砖。

不久之后,我希望做一个类似的重写系统,可以放置追踪实体如障碍、资源补充点等。现在,当动画开始时,它们进入屏幕时就会被激活,离开屏幕时就会失效。我希望在飞快运行时排列它们,做出像地形图层时那样好的循环效果。这就是无穷无尽模式的基础。(本文为游戏邦/gamerboom.com编译,拒绝任何不保留版权的转载,如需转载请联系:游戏邦

Two types of one-directional terrain animation

by Dan FitzGerald

In Dog Sled Saga, the terrain you traverse only moves leftward, and there are several layers of terrain at different distances from the “camera.” At first, we only had one terrain tile per layer, which allowed for a fairly simple animation routine. As we begin to make new tiles of various lengths, though, a rewrite was necessary.

Originally, when the layers of terrain were made up of identical tiles of equal width, each layer was a block of tiles wide enough to cover the screen width, plus one extra.

Each layer slid left at its set parallax speed, and once it had moved the distance of one tile width (i.e. the leftmost tile was completely off-screen) it would bounce back to the right the distance of one tile width. The apparent motion of the terrain was seamless, and no more tiles were produced than needed.

This system was been in place since back when I had plain quads with colored edges for terrain. However, I knew that this was a placeholder system. We planned to be able to have randomized tiles of arbitrary width, with things like buildings, patches of grass, snow drifts, mountains, and so on. This cannot work if the terrain layer is a set block.

I wrote a new system that cuts tiles off the left edge of the layer when they leave the screen and adds new ones (with shufflebag randomization based on a C# tutorial that I didn’t struggle to implement in AS3) to the right as soon as the exposed right edge of the layer is about to appear. Common tiles are drawn from a Loanshark-based object pool (when they are removed, they are made available to be reused, so new tile objects aren’t created every time) while rare tiles are produced as needed.

There’s only one irregularly sized tile so far, but this opens the door for many more to come.

Soon, I want to do a similar rewrite of the system that places track entities like obstacles and restock points. Right now, they are set when the race starts, and activated/deactivated as enter/leave the screen. I want to queue them on the fly and do better recycling like I did with the terrain tiles. This will open the door for an endless mode.(source:gamasutra)


上一篇:

下一篇: