C++ 中的横向卷轴

发布于 2024-12-09 04:57:40 字数 281 浏览 1 评论 0原文

我正在考虑使用 OpenGL 和 C++ 创建一个基本的横向卷轴,但是我在解决一些基本概念问题时遇到了麻烦,即:

  1. 将窗口划分为简单的“块”(某种网格系统)。我想在什么级别上做到这一点? (OpenGL 视口大小,或者通过某种抽象来确保使用 x 的倍数?)

  2. 存储所有这些“块”的数据以允许碰撞检测和一些特殊效果。解决这个问题的明智方法是什么 - 我正在考虑对象的多维数组(其中包含图块类型等信息),但这似乎不是一个非常优雅或有效的解决方案。

I'm looking at creating a basic side-scroller using OpenGL and C++, however I'm having trouble tackling a few basic conceptual issues, namely:

  1. Dividing the window into easy "blocks" (some sort of grid system). On what level would I want to do this? (The OpenGL viewport size, or through some abstraction that ensures working with multiples of x?)

  2. Storing the data for all these "blocks" to allow for collision detection and some special effects. What's a sensible way of going about this - I was thinking along the lines of a multi-dimensional array of objects (which contain information such as the tile type), but this doesn't seem like a very elegant or efficient solution.

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

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

发布评论

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

评论(2

等往事风中吹 2024-12-16 04:57:40

通常,不是窗口(即视口)被划分为网格,而是“游戏区域”。根据您的艺术风格选择合适的尺寸(例如 64px - 出于技术原因,您可能需要选择 2 的幂的尺寸)并为您的游戏创建该尺寸的图块(作为一维数组存储和加载) )

然后,这些图块在图块地图中被引用(通过偏移量),它实际上描述了您的关卡的样子。每个图块还可以有额外的元数据来处理碰撞和游戏事件。您可能希望使用现有的地图格式和工具集来节省时间,例如 Mappy。

Usually, it isn't the window (ie. viewport) which is divided into a grid but rather the "gameplay area". Pick a good size according to the style of your art (something like 64px - you might want to select a size that is a power of two for technical reasons) and create tiles of that size for your game (stored and loaded as a 1D array)

Then, these tiles are referenced (by an offset) in a tilemap, which actually describes what your level looks like. Each tile can also have extra metadata for handling collisions and game events. You might want to use an existing map format and toolset to save time, like Mappy.

π浅易 2024-12-16 04:57:40

提示:
分别考虑显示和数据(查找模型-视图-控制器)。

如何存储数据取决于数据的访问方式,而不是数据的显示方式。从计算机的角度来思考!

提示,在数据的一维存储中工作并计算出下一个上/下点的位置通常比在二维中工作更容易。

Tips:
Think of the display and the data separately (lookup Model-View-Controller).

How you store the data depends on how it's going to be accessed, not on how it's going to be displayed. Think of it from the computers point of view!

Hint, it's often easiest to work in a one dimensional storage of the data and work out where along it the next point up/down is than work in 2d.

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