在等距世界中移动瓷砖之间的精灵

时间:2022-07-27 08:57:16

I'm looking for information on how to move (and animate) 2D sprites across an isometric game world, but have their movement animated smoothly as the travel from tile to tile, as opposed to having them jump from the confines of one tile, to the confines of the next.

我正在寻找有关如何在等距游戏世界中移动(和动画)2D精灵的信息,但是他们的动作在从一个瓷砖到另一个瓷砖的旅行中平滑地动画,而不是让它们从一个瓷砖的范围跳到下一个的限制。

An example of this would be in the Transport Tycoon Game, where the trains and carriages are often half in one tile and half in the other.

这方面的一个例子是运输大亨游戏,其中火车和车厢通常是一个瓦片的一半而另一个是一半。

3 个解决方案

#1


Drawing the sprites in the right place isn't too difficult. The projection formula are:

在正确的地方画出精灵并不太难。投影公式为:

screen_x = sprite_x - sprite_y
screen_y = (sprite_x + sprite_y) / 2 + sprite_z

sprite_x and sprite_y are fixed point values (or floating point if you want). Usually, the precision of the fixed point is the number of pixels on a tile - so if your tile graphic was 32x16 (a projected 32x32 square) you would have 5 bits of precision, i.e. 1/32th of a tile.

sprite_x和sprite_y是固定点值(如果需要,可以是浮点值)。通常,固定点的精度是图块上的像素数 - 因此,如果您的图块图形为32x16(投影的32x32正方形),则您将具有5位精度,即图块的1/32。

The really hard part is to sort the sprites into an order that renders correctly. If you use OpenGL for drawing, you can use a z-buffer to make this really easy. Using GDI, DirectX, etc, it is really hard. Transport Tycoon doesn't correctly render the sprites in all instances. The original Transport Tycoon had the most horrendous rendering engine you've ever seen. It implemented the three zoom levels are three instanciations of a massive masm macro. TT was written entirely in assembler. I know, because I ported it to the Mac many years ago (and did a cool version for the PS1 dev kit as well, it needed 6Mb though).

真正困难的部分是将精灵分类为正确渲染的顺序。如果使用OpenGL进行绘图,则可以使用z缓冲区来实现这一点。使用GDI,DirectX等,真的很难。在所有情况下,Transport Tycoon都无法正确渲染精灵。最初的Transport Tycoon拥有你见过的最可怕的渲染引擎。它实现了三个缩放级别是一个巨大的masm宏的三个实例。 TT完全是用汇编语言编写的。我知道,因为我多年前将它移植到Mac上(并为PS1开发套件做了很酷的版本,但它需要6Mb)。

P.S. One of the small bungalow graphics in the game was based on the house Chris Sawyer was living in at the time. We were tempted to add a Ferrari parked in the driveway for the Mac version as that was the car he bought with the royalties.

附:游戏中的一个小平房图形基于Chris Sawyer当时居住的房子。我们很想添加一辆停在Mac车道上的法拉利车,因为这是他用特许权使用费购买的车。

#2


Look up how to do linear interpolation (it's a pretty simple formula). You can then use this to parameterise the transition on a single [0, 1] range. You then simply have a state in your sprites to store the facts:

查看如何进行线性插值(这是一个非常简单的公式)。然后,您可以使用它来参数化单个[0,1]范围内的转换。然后你只需在你的精灵中有一个状态来存储事实:

  1. That they are moving
  2. 他们正在移动

  3. Start and end points
  4. 起点和终点

  5. Start and end times (or start time and duration
  6. 开始和结束时间(或开始时间和持续时间

and then each frame you can draw it in the correct position using an interpolation from the start point to the end point. Once you have exceeded the duration, the sprite then gets updated to be not-moving and positioned in the end point/tile.

然后使用从起点到终点的插值将每个帧绘制到正确的位置。一旦超过持续时间,精灵就会更新为不移动并定位在终点/平铺中。

#3


Why are you thinking it'll jump from tile to tile? You can position your sprite at any x,y co-ordinate.

你为什么认为它会从一块瓷砖跳到另一块瓷砖?您可以将精灵定位在任何x,y坐标上。

First create your background screen buffer and then place your sprites on top of it.

首先创建背景屏幕缓冲区,然后将精灵放在它上面。

#1


Drawing the sprites in the right place isn't too difficult. The projection formula are:

在正确的地方画出精灵并不太难。投影公式为:

screen_x = sprite_x - sprite_y
screen_y = (sprite_x + sprite_y) / 2 + sprite_z

sprite_x and sprite_y are fixed point values (or floating point if you want). Usually, the precision of the fixed point is the number of pixels on a tile - so if your tile graphic was 32x16 (a projected 32x32 square) you would have 5 bits of precision, i.e. 1/32th of a tile.

sprite_x和sprite_y是固定点值(如果需要,可以是浮点值)。通常,固定点的精度是图块上的像素数 - 因此,如果您的图块图形为32x16(投影的32x32正方形),则您将具有5位精度,即图块的1/32。

The really hard part is to sort the sprites into an order that renders correctly. If you use OpenGL for drawing, you can use a z-buffer to make this really easy. Using GDI, DirectX, etc, it is really hard. Transport Tycoon doesn't correctly render the sprites in all instances. The original Transport Tycoon had the most horrendous rendering engine you've ever seen. It implemented the three zoom levels are three instanciations of a massive masm macro. TT was written entirely in assembler. I know, because I ported it to the Mac many years ago (and did a cool version for the PS1 dev kit as well, it needed 6Mb though).

真正困难的部分是将精灵分类为正确渲染的顺序。如果使用OpenGL进行绘图,则可以使用z缓冲区来实现这一点。使用GDI,DirectX等,真的很难。在所有情况下,Transport Tycoon都无法正确渲染精灵。最初的Transport Tycoon拥有你见过的最可怕的渲染引擎。它实现了三个缩放级别是一个巨大的masm宏的三个实例。 TT完全是用汇编语言编写的。我知道,因为我多年前将它移植到Mac上(并为PS1开发套件做了很酷的版本,但它需要6Mb)。

P.S. One of the small bungalow graphics in the game was based on the house Chris Sawyer was living in at the time. We were tempted to add a Ferrari parked in the driveway for the Mac version as that was the car he bought with the royalties.

附:游戏中的一个小平房图形基于Chris Sawyer当时居住的房子。我们很想添加一辆停在Mac车道上的法拉利车,因为这是他用特许权使用费购买的车。

#2


Look up how to do linear interpolation (it's a pretty simple formula). You can then use this to parameterise the transition on a single [0, 1] range. You then simply have a state in your sprites to store the facts:

查看如何进行线性插值(这是一个非常简单的公式)。然后,您可以使用它来参数化单个[0,1]范围内的转换。然后你只需在你的精灵中有一个状态来存储事实:

  1. That they are moving
  2. 他们正在移动

  3. Start and end points
  4. 起点和终点

  5. Start and end times (or start time and duration
  6. 开始和结束时间(或开始时间和持续时间

and then each frame you can draw it in the correct position using an interpolation from the start point to the end point. Once you have exceeded the duration, the sprite then gets updated to be not-moving and positioned in the end point/tile.

然后使用从起点到终点的插值将每个帧绘制到正确的位置。一旦超过持续时间,精灵就会更新为不移动并定位在终点/平铺中。

#3


Why are you thinking it'll jump from tile to tile? You can position your sprite at any x,y co-ordinate.

你为什么认为它会从一块瓷砖跳到另一块瓷砖?您可以将精灵定位在任何x,y坐标上。

First create your background screen buffer and then place your sprites on top of it.

首先创建背景屏幕缓冲区,然后将精灵放在它上面。