2D 渲染 - 从后到前不同高度

发布于 2024-09-11 09:11:15 字数 1310 浏览 2 评论 0原文

我想知道渲染由多个尺寸的图块组成的场景的最佳方法是什么,从后到前,具有不同的高度。

像这样:http://www.youtube.com/watch?v=Ahfrxm6ETgA
重要的事情从 2:35 开始。请忽略可怕的叙述。 :P

我正在使用 VB2008。

这就是我现在所拥有的:

  • 我的图形由位图组成, 宽度和长度可除以 32.
  • 对象与分配给它们的图形具有相同的尺寸。
  • 对象具有图层,较低的图层在移动到下一层之前从后到前绘制(例如,图层 0 中的所有对象在图层 1 中的对象之前渲染)
  • 所有对象,无论风景/玩家/人物/实体如何都被存储一起在 MapObject 列表中。

这也是我不确定是否保留的内容

  • 对象的排序不是基于其初始 X/Y 值,而是基于其 X/Y+高度值。这样,对象就会根据它们“接触”运动场的位置进行渲染。 例如,X/Y = 树对象的顶部,X/Y = 树对象的树干。
  • 人(包括玩家)将只是在一个巨大的排序中渲染和更新的法线地图对象列出每一帧。

有什么建议吗?现在,修改我的代码可以让我的玩家(32x64 像素)站在建筑物前,但她的脚与一片草重叠,这是行不通的。然而,改变排序算法会让玩家消失在建筑物中,但你可以看到她的脚。

所以有点不对劲哈哈。

有人有 2D 渲染经验可以帮助我吗?

另外,我的玩家是否应该包含在地图对象列表中?当然,这些只是存储在其他地方的数据的图形表示(地图更改时不会被清除),或者我应该将它们放入一个全新的渲染列表中(这可能会带来全新的问题)。

谢谢!〜

编辑:我刚刚在这里读到这个 http://xnafantasy .wordpress.com/2008/07/22/rendering-dilemmas-z-ordering-grass-and-camera-clipping/

据他所说,他有 4 个不同的层,然后在第 3 层和第 3 层之间绘制演员4,第 4 层是始终出现在人的顶部的物体。因此,他的玩家似乎不是地图对象,而是与其他所有物体分开渲染的演员。

嗯。

I'm wondering what the best way to render a scene made up of multiple-sized tiles, from back to front, with different heights.

Like this: http://www.youtube.com/watch?v=Ahfrxm6ETgA
Important stuff starts at 2:35. Ignore the horrible narration. :P

I'm using VB2008.

So here's what I have right now:

  • My graphics consist of bitmaps that
    have widths and lengths divisible by
    32.
  • Objects have the same dimensions as the graphic they were assigned.
  • Objects have layers, with lower layers being drawn back-to-front before moving onto the next layer (e.g., all objects in layer 0 get rendered before objects in layer 1)
  • ALL objects, regardless of scenery/player/person/entity are stored together in a List of MapObject.

Here is what I have also that I'm not sure to keep

  • Objects are sorted based on not their initial X/Y value, but their X/Y+Height value. That way, objects are rendered based on where they 'touch' the playing field. E.g., X/Y = top of a tree object, X/Y = trunk of the tree object.
  • People (including the player) will be just normal map objects that get rendered and updated within a huge sorted list every frame.

Any suggestions? Right now, fudging around with my code allows my Player (32x64 pixels) to stand infront of a building but has her feet get overlapped with a patch of grass, which doesn't work. However, changing the sorting algorithm makes the player disappear in the building but you can see her feet.

So something is wrong haha.

Anyone have experience with 2D rendering that could help me out?

Also, should my players be included with the list of map objects? Granted, these will only be graphical representations of their data stored elsewhere (won't be cleared when map changes), or should I throw them into a whole new rendering list (which might open whole new problems).

Thank you!~

EDIT: I just read this here
http://xnafantasy.wordpress.com/2008/07/22/rendering-dilemmas-z-ordering-grass-and-camera-clipping/

From what he says, he has 4 different layers and then draws the actor between Layer 3 and 4, with layer 4 being objects that will always appear on-top of the person. So, it appears that his player isn't a map object but an actor rendered separately from everything else.

Hmmm.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟─花易冷 2024-09-18 09:11:15

老实说,我会使用包含按高度排序的列表的 2D 数组(用于 x,y 坐标)。

假设您不需要旋转景观,您应该能够以简单的顺序访问阵列,从较远的图块开始,然后绘制较近的图块。绘制图块时,您可以将最低的对象绘制到最高的对象(空列表可能意味着绘制默认的底色)。

关于玩家/角色对象的位置,我想它们只能在空的方块中?在这种情况下,特殊情况是空的瓷砖绘制代码来检查是否有人在那里并在绘制地面后绘制他们。

To be honest, I would use a 2D array (for the x,y coordinates) containing a list ordered by height.

Assuming you do not need to rotate the landscape, you should be able to visit the array in a simple order, starting with the further away tiles and then drawing the closer ones. While drawing a tile, you would draw the lowest object there up to the highest (an empty list could mean draw the default ground colour).

Regarding the position of the player/character objects, I imagine they can only be in empty tiles? In which case special case the empty tile drawing code to check if someone is there and draw them after drawing the ground.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文