XNA 2d 街机游戏精灵跟随

发布于 2024-10-07 08:04:00 字数 165 浏览 0 评论 0原文

我将制作一个类似 XNA 示例游戏“Platformer1”的游戏,它随 XNA 一起提供。但我需要更长的关卡,这些关卡不适合屏幕(例如超级马里奥关卡)。我怎样才能达到这样的水平呢?我需要使用跟随精灵的 2D 相机吗?如果我这样做,我该如何加载关卡?我有点困惑,我不确定是否可以清楚地解释我的问题。希望有人能帮忙吗?

I am going to make a game like XNA example game "Platformer1" which comes with the XNA. But I need longer levels which doesn't fit in the screen (like Super Mario levels). How can I manage this kind of level? Do I need to use a 2d camera that follows the sprite? If I do this way how can I load the level? I am a bit confused and I am not sure if I could explain my problem clearly. Hope someone can help?

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

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

发布评论

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

评论(5

那伤。 2024-10-14 08:04:00

本教程基于平台入门套件 MSDN 中的 有一个步骤 添加滚动级别< /a> 指导您创建更长的关卡。教程非常详细,强烈推荐。

我在 XNA Game Studio 4.0 部分找不到教程,但差异应该很小。根据页面底部的注释,您只需更改

spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None, cameraTransform);

的替换即可。

spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise, null, cameraTransform);

教程代码中

The tutorial based on Platformer Starter Kit in MSDN has a step Adding a Scrolling Level which guides you through creation of longer levels. The tutorial is very detailed, I highly recommend it.

I couldn't find the tutorial in the section for XNA Game Studio 4.0, but differences should be minimal. According to the comment at the bottom of the page, all you need to change is replace

spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None, cameraTransform);

with

spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise, null, cameraTransform);

in the tutorial code.

野味少女 2024-10-14 08:04:00

如果你想创建一个横向滚动游戏,那么我会研究视差滚动。快速搜索 google/bing 将帮助您找到大量教程。另外,另一个有用的提示是在 YouTube 上搜索 XNA 视频,我们有很多海报分享了他们的源代码。

以下是 Microsoft 视差滚动 的链接。

If you want to create a side scrolling game, then I would look into parallax scrolling. A quick google/bing will help you find lots of tutorials. Also, another useful tip is to search YouTube for XNA videos has we a lot of posters share their source code .

Here is a link to Microsofts Parallax Scrolling.

山人契 2024-10-14 08:04:00

听起来你面前有一些问题。

但是我需要更长的关卡,但不适合屏幕(例如超级马里奥关卡)。我怎样才能管理这种级别。

有多种方法可以做到这一点,但一种相当简单的方法是使用名为 Tile 的类的二维数组(或稀疏数组,具体取决于您的级别有多大),该类存储有关平铺图像、动画……等等。

是的,您可能需要一台“相机”。这可以很简单,只需绘制该阵列的特定范围或使用变换来缩小并在关卡中平移的功能更强大的相机。

希望这将帮助您入门。

Sounds like you have a few problems ahead of you.

But I need longer levels which doest'n fit in the screen(like super mario levels). How can I manage this kind of levels.

There are several ways to do this, but a fairly easy way would be to have a 2d array (or sparse array, depending on how large your levels are) of a class named Tile that stores info about the tile image, animation, ...whatever.

Yes, you'll probably want a "camera". This can be as simple as only drawing a certain range of that array or a more featured camera that uses transforms to zoom out and translate across your level.

Hopefully this will help get you started.

飘然心甜 2024-10-14 08:04:00

我在 XNA 中做了相当多的工作,根据我的经验,有 2 种方法可以绘制 2D 场景:

1) 严格 2D。这种方法更容易,但有一些限制。本身并没有“相机”,你所做的就是将所有东西移动到固定的 2D“相机”下面。我在引号中说“相机”,因为相机是固定的(据我所知)。优点是它很容易,缺点是你不能轻松地放大或缩小或做其他相机效果。

2) 3D 中的 2D。使用 2D 平面设置 3D 世界。这更灵活,但使用起来也更具挑战性,因为您需要设置 3D 世界和 3D 相机。如果这是您第一次尝试制作游戏,我强烈建议您不要使用这种方法。

我实际上只熟悉严格的 2D 方法,并且您需要一个具有 2D 坐标的地图对象列表。您还需要存储您正在查看的地图的哪个部分,我使用存储它的 Rectangle 或 Vector2 来执行此操作。该值将随着角色的移动而向前移动。然后,您可以获取 2D 地图对象的坐标并减去您正在查看的左上角的 (X,Y),以确定对象的屏幕位置。所以:

float screenX = myMapObject.X - focusPoint.X;
float screenY = myMapObject.Y - focusPoint.Y;

另一件事要注意,使用浮点数或 Vector2/3 来存储位置,你可能认为现在不需要它,但它会被淘汰。

这可能有点过头了,但我的 SF 项目使用 XNA 绘制一个可以移动的严格 2D 场景:http:// /sourceforge.net/projects/asteroidoutpost/

我希望这会有所帮助。

I've done a decent amount of work in XNA, and from my experience, there are 2 ways to draw a 2D scene:

1) Strictly 2D. This method is much easier, but has a few limitations. There is no "camera" per se, what you do is move everything underneath the fixed 2D "camera". I say "camera" in quotes because the camera is fixed (as far as I know). The upside is that it's easy, the downside is that you can't easily zoom in or out or do other camera effects.

2) 2D in 3D. Set up a 3D world with a 2D plane. This is more flexible, but is also more challenging to work with because you will need to set up a 3D world and 3D camera. If this is your first attempt with making a game, I would highly recommend against this method.

I'm really only familiar with the strictly 2D method, and you would want a list of map objects that have a 2D coordinate. You would also want to store which section of the map you are looking at, I do this with a Rectangle or Vector2 that stores this. This value would move forward as the character moves. You can then take your 2D map objects' coordinate and subtract the (X,Y) of the top-left of what you are looking at to determine an object's screen position. So:

float screenX = myMapObject.X - focusPoint.X;
float screenY = myMapObject.Y - focusPoint.Y;

An other thing to note, use floats or Vector2/3 to store locations, you may not think it's required now, but it will be down the line.

It might be overkill, but my SF project uses XNA to draw a Strictly 2D scene that you can move around: http://sourceforge.net/projects/asteroidoutpost/

I hope this helps.

避讳 2024-10-14 08:04:00

看看 Nick Gravelyns 的教程。当我刚开始接触时,他们给了我很多帮助——真的值得一看,可以学到很多 2D 游戏的知识。

所有视频均已在 YouTube 此处上发布

Have a look at Nick Gravelyns tutorials. They helped me tonne when I was first starting out - Really really worth a look for learning a lot on 2D games.

All the videos are now on youtube here

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