如何在 2D Actionscript / Flex 3 (flash) 游戏中创建地图滚动?
我正在 Flash 的太空环境中创建 2D 多人游戏(带有 Flex Builder 3 的 ActionScript 3)。 玩家的角色(一艘船)将始终位于中心。 因为它必须看起来像船在移动,而实际上它始终位于中心,所以背景和所有环境对象都必须以相反的方式移动。
我对如何做到这一点的想法是创建一个引用环境中所有对象的数组。 然后它们将被循环,并且它们的位置将沿船舶运动的相反方向改变。
然而,我担心这看起来不会顺利,或者会太慢。 大概会造成“口吃”吧? 因此,在我开始开发这样的系统之前,我想知道是否有更好的选择 - 或者是否有人对我想做的事情有经验。
提前致谢。
I'm creating a 2D multiplayer game in a space environment in flash (actionscript 3 with flex builder 3). The player's character (a ship) will always be in the center. Because it has to look like the ship is moving, while it is actually always in the center, the background and all environmental objects have to move the opposite way.
My thought on how to do this would be to create an array with references to all objects in the environment. These will then be looped and their position will be changed in the opposite direction of the ship's movement.
I am however afraid that this will not look smooth, or will be too slow. It will probably cause "stuttering"? Because of that, before I start developing such system, I would like to know if there are better options - or if anyone has experience with what I want to do.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,这是最有效的方法...并隐藏所有不在屏幕上的项目,以节省性能...如果这些对象仅移动,那么您应该考虑 flash.display.DisplayObject::cacheAsBitmap,为了获得更好的性能...
替代方法是,将所有项目放入一个精灵中,遮盖它,然后在精灵周围移动...这只有在你的世界有限的情况下才能正常工作...并且只有在它很小的情况下才会正常执行...所以我猜,它是没有选择...
greetz
back2dos
no, that's the most efficient approach ... and hide all items, that are not on screen, to save performance ... if those object only move, than you should consider flash.display.DisplayObject::cacheAsBitmap, for better performance ...
the alternative would be, to put all items into one Sprite, mask it, and then move around the Sprite ... this will only work properly if your world is limited ... and will only perform ok, if it is small ... so i guess, it's no option ...
greetz
back2dos
好吧,您将需要跟踪所有对象,但在任何给定时间您实际上只需要担心其中的一小部分。
一种简单的方法是将您的游戏区域划分为象限网格(您最终使用多少个象限将取决于您)。 单个象限可以包含多个不同的显示元素。 然后你只需要弄清楚你的船位于哪个方格。从中你可以通过绘制船周围的区域来计算出需要扫描的最小象限数。
当元素在游戏区域中移动时,您只需要确保它们不断更新它们所在的象限。
Well, you will need to keep track of all of the objects, but you should only have to actually worry about a small amount of them at any given time.
One simple way of doing this would be to divide your play area into a grid of quadrants (how many you end up using will be up to you). A single quadrant could contain multiple different display elements. Then you just have to figure out which square your ship is located in. From that you can figure out the minimum number of quadrants you need to scan through draw the area around the ship.
As elements move around the play area you just need to make sure that they constantly update which quadrant they are located within.
由于它是一款多人游戏,布兰登霍尔的方法更适合您的需求,因为您可以轻松地发送玩家周围存在另一艘船的通知(这比向用户提供所有非船舶的信息要好)周围的屏幕元素)我只想补充一点,根据视口的大小,屏幕上的象限数量可能会有所不同,您应该始终检查当前象限的边界,以查看视口上是否显示相邻象限。
As it is a multiplayer game, Branden Hall's approach is much more suited to your needs, as you could easily send notification of the existance of another ship in the surrounding of the player (it's better than giving the user the information of all the non-onscreen elements of their surrounding) I will just add that, depending on the size of your viewport, the number of quadrants on screen could vary, you should always check your current quadrant's boundries to see if adyacent quadrants are being displayed on the viewport.