如何存储 2D 横向卷轴游戏的屏幕对象?

发布于 2024-10-05 01:31:43 字数 396 浏览 0 评论 0原文

我正在尝试找出在二维横向滚动游戏上存储地图对象的最佳方法。

例如,在 Doodle Jump 游戏中,您跳跃的平台如何存储?

我对如何完成它有一些想法。

平台是否存储在字符串或其他定义每个平台将放置的位置的对象中?例如,如果我定义了一个字符串,如 0,10,5,8,6,2,3,4,2,..... 等等,我可以将它们解释为游戏中每个游戏块的 x 坐标。我想问题在于可能需要定义很多游戏片段。游戏似乎是无尽的,所以预先定义地图似乎是一个坏主意。

我还认为这些碎片可能只是随机的。因此,每当地图需要新的地图片段时,它都会随机获得一个 x 坐标。我认为这似乎非常可行,但在玩 DoodleJump 时,它们似乎并不都是随机的。

有谁知道如何存储这些地图对象以引导我走向正确的方向?

谢谢!

I'm trying to figure out the best way to store map objects on a 2d side scrolling game.

For example, in the game Doodle Jump, how do the platforms you jump on get stored?

I've had a few thoughts about how it is possibly done..

Are the platforms stored in a string or other object that defines where each platform is going to be placed? For example if I defined a string like 0,10,5,8,6,2,3,4,2,..... and so on, I could interpret those as x-coordinates of each game piece in the game. I guess the problem with this is that could potentially be A LOT of game pieces to define. The game appears to be endless, so pre-defining the map seems like a bad idea.

I also thought that maybe the pieces are just random. So whenever the map calls for a new map piece, it randomly gets an x-coordinate. I thought this seemed pretty feasible but when playing DoodleJump it doesn't appear that they are all random.

Does anyone have any idea on how these map objects could be stored to lead me in the right direction?

Thanks!

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

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

发布评论

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

评论(3

鯉魚旗 2024-10-12 01:31:43

我正在考虑一个增量高度坐标及其各自的宽度坐标(一维或二维数组)的数组。增量是因为不让坐标变大。
您可以使用屏幕尺寸来了解要计算屏幕坐标的平台。当跳跃的物体达到一定的屏幕高度阈值时,移动相机,计算新的屏幕坐标,忽略掉出屏幕的平台并添加进入视野的平台。

您可以使用具有一定随机性且对坐标距离具有最小/最大约束的算法预先生成数组。当使用整数时,我猜你可以在遇到麻烦之前生成一个相当大的数组。
或者使用随机函数的相同种子实时生成它,因此每次都会生成相同的数组,并且您可以无限期地继续下去

I'm thinking an array of incremental height coordinates and their respective width coordinates (1d or 2d array). Incremental because of not letting the coordinates get to big.
You can use the screensize to know which platforms to calculate screen coordinates for. When the jumping object reaches a certain screenheight threshold, shift the camera with it, calculating new screen coordinates, omitting platforms that fall off screen and adding platforms that come within view.

You could generate the array beforehand using an algorithm with some randomness with a min/max constraint on coordinate distance. When using ints, you could generate a pretty big array before getting into trouble I guess.
Or generate it real-time using the same seed for the random function, so it will generate the same array every time and you can keep going indefinitely

吃兔兔 2024-10-12 01:31:43

您可以使用每个级别具有固定种子的随机数生成器,以便用户每次都获得相同的级别。随机数可以从适当值的数组中选择。 (我已经在 Android 游戏中成功使用了它。)

You could use a random number generator with a fixed seed per level so users get the same level every time. The random numbers can select from an array of appropriate values. (I've used this successfully in an android game.)

错爱 2024-10-12 01:31:43

许多平台游戏将静态地图平台(即地图中无法操纵/破坏的部分 - 例如《马里奥兄弟》中的地砖)存储为预定义地图。这可以使用值数组或 alphamap 图像来完成。

如果您使用数组方法,请使用字节(unsigned char's)而不是int's。

A lot of platform games store the static map platforms (that is, the parts of the map that cannot be manipulated/destroyed - the floor tiles in Mario Bros., for example) as either predefined map. This can be done using an array of values or an alphamap image.

If you use the array method, use bytes (unsigned char's) instead of int's.

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