增加 Flash 场景长度
我正在制作一款横向卷轴 Flash 游戏。该关卡是预先制作的,因此不会在运行时生成任何对象。现在我把这个关卡做得很长,但在编辑器窗口中它突然停止了。但在游戏中它仍然滚动。
这是在编辑器中。可以看到滚动条不能再向左移动了:
游戏中:
该关卡比编辑器中显示的要长。起初,它只是在场景的边界放置一个物体来增加它。但这不再起作用了。如何增加场景宽度?
I am making a side scrolling flash game. The level is pre-made so there aren't objects which spawn on runtime. Now I made this level quite long, but in the editor window it suddenly stops. But in game it still scrolls on.
This is in the editor. You can see that the scroll bar can't go left any more:
And in game:
The level is longer than then shown in editor. At first it was just putting an object at the border of the scene to increase it. But that won't work anymore. How can I increase the scene width?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在任何给定时间,您可以在舞台上显示的图像的大小是有限的。您似乎正在突破该限制,这就是您无法再查看的原因。
造成这种情况的原因有多种,但归根结底是这样一个事实:就 Flash 进程而言,Flash DisplayList 相对较慢。当您在舞台上处理大量对象时,Flash 必须了解每一个对象,如果对象数量超出您的需要,您将获得糟糕的性能。
但是,不要绝望!有一些方法可以解决这个问题。
您需要了解的第一件事是,此限制适用于舞台上的位图。您的项目中可以有一个非常非常大的位图 - 只要您不尝试一次显示整个内容。
大多数游戏框架解决这个问题的方式是这样的:
1)您在幕后存储所有图像数据,并在那里进行所有图像处理等。
2) 在每一帧上,您使用 copyPixels() 来抓取较大图像中将出现在舞台上的部分。这意味着,如果您的舞台视图仅显示 640x480 像素,那么您只需复制出等于这些尺寸的较大图像的一部分即可。
3) 在舞台上,您只有一个位图,您可以将第二步中的 copyPixels() 中的位图数据写入其中。
这称为“Blitting”,如果这听起来有点复杂,那是因为它确实如此。然而,正如我所说,许多游戏框架将为您完成繁重的工作。查看 Flixel 或 PushButtonEngine,它们是两个最流行的框架。
听起来您当前的方法需要进行一些调整才能使其以这种方式工作,但从长远来看,我会推荐它 - 您的游戏将变得更易于管理,您将获得更好的性能,并且您赢了不必求助于其他类型的黑客来让你的关卡全程加载。
(快速而简单的解决方案是将背景分解为多个图像,然后随时交换它们,但是同样,这会给渲染引擎带来大量工作,而这通常不是您想要承担繁重工作的地方)。
祝你好运!
There is a limit to the size of the image you can display on the stage at any given time. It looks like you're probably pushing up against that limit, which is why you can't view any more.
There are various reasons for this, but it boils down to the fact that the flash DisplayList is relatively slow, as far as a Flash processes go. When you're dealing with a lot of stuff on the stage, Flash has to be aware of every single object, and you're going to get terrible performance if you have more on there than you need to.
But, don't despair! There are ways around this issue.
The first thing you need to know is that this limit is for bitmaps on the stage. You can have a bitmap in your project that's much, much bigger - as long as you're not trying to display the whole thing at once.
The way most gaming frameworks solve this problem is like this:
1) You store all of your image data behind-the-scenes, and you do all of your image manipulation etc there.
2) On every frame, you use copyPixels() to grab just the part of your larger image that would appear on the stage. That means if your stage view is only showing, for instance, 640x480px then you would just copy out a portion of your larger image equal to those dimensions.
3) On the stage you just have a single bitmap into which you write the bitmap data from the copyPixels() in step two.
This is called "Blitting" and if this sounds a bit complicated that's because it is. However, as I said many of the gaming frameworks will do the heavy lifting for you. Check out Flixel or PushButtonEngine, those are the two most popular frameworks.
It sounds like your current approach would require a bit of tweaking in order to make it work that way, but in the long run I'd recommend it - your game will become much more manageable, you'll get much better performance and you won't have to resort to some other kind of hackery in order to get your levels to load the whole way.
(The quick and easy solution would be to break your background into several images and just swap them out as you go, but again - that's putting a lot of work onto the rendering engine, which is generally not where you want to put your heavy lifting).
Good luck!