什么是管理的flash游戏的游戏水平的最佳方法是什么? [英] What is the best way to manage game levels in flash games?

查看:144
本文介绍了什么是管理的flash游戏的游戏水平的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍然在学习,我想设计游戏关卡我的第一场比赛(的平台之一)。

I am still learning and I am trying to design the game levels for my first game(a platform one).

我有一些简单的问题,因为我觉得我是在错误的道路。

I have some straightforward questions because I feel I am on the wrong way.

如果每个级别都有自己的类?

的方式,我试图做的是,当一个人完成第一级我设置为null,涉及到这个类中的变量,注销所有事件,然后从舞台上删除所有的孩子,叫第二层构造,不宣而任何变量,新的2级();和为了拯救的进展情况下,一个想再次发挥了水平设置为true静止无功。

The way I am trying to do is, when one finishes the first level I set to null the variables that pertains to that class, unregister all events and remove all children from the stage, call a second level constructor, without declaring any variable, new level2(); and set to true a static var "in order to save" that progress in case one wants to play that level again.

但是我看到了code变得凌乱,我碰到的问题,和内存管理问题这么多。

我搜查了所有在互联网上,但我找不到解释的详细信息任何教程,所以我尝试实现我想要的很多,但我现在真的需要一些建议对它不会迷路。

I searched it for all over the internet but I can't find any tutorial that explain it in details, so I'm trying out many ways of achieving what I want, but now I am really in need of some advices on it to not get lost.

在此先感谢。

推荐答案

我总是使用二维数组,写两个功能很喜欢:

I always liked using 2D arrays and writing 2 functions:

  1. 系统功能的阵列存储为一个字符串
  2. 系统函数的字符串转换回二维数组

这些功能将是一个 LevelManager 类的一部分,这也将有一些功能是这样的:

These functions would be part of a LevelManager class which would also have some functions like this:

  • 负载(levelData:字符串):无效 - 加载基于级别的数据串的水平
  • 卸载():无效 - 卸载当前水平
  • 交换(levelData:字符串):无效 - 卸载目前的水平,然后加载一个新的水平 - 一个很好的功能,把一个中场休息动画
  • 保存():字符串 - 保存当前水平(环通目前present敌人,创造新级别的数据,这将返回
  • objectFromSnip(中略:字符串):无效 - 生成一个片段一个对象(到一个字符串psented即单个对象重新$ P $ - 见下文)。我通常在 $ 通过所产生的属性集打破下方分开,然后循环,并调用这个函数在他们身上。
  • load(levelData:String):void - loads a level based on level data string
  • unload():void - unloads the current level
  • swap(levelData:String):void - unloads the current level and then loads a new level - a good function to put an intermission animation in.
  • save():String - saves the current level (loop through currently present enemies and create new level data, which will be returned
  • objectFromSnip(snip:String):void - generate an object from a snippet (ie a single object represented by a string - see below). I normally break the below apart at the $ and then loop through the resulting sets of properties and call this function on them.

该级别的数据可能看起来像这样:

The level data could look like this:

object#x#y$object2#x#y

其中, $ 重presents对象和重$ P $的分离psents分离属性的对象。

Where $ represents the separation of objects and # represents the separation of properties for that object.

再此presentation数组是:

The array representation of this would be:

[
    [object, x, y],
    [object2, x, y]
]

对于创建的对象,基本上你想要做的是:

As for the creation of the object, basically what you want to do is:

  • 使用<一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html?filter_flash=cs5&filter_flashplayer=10.2&filter_air=2.6#getDefinitionByName%28%29"相对=nofollow> getDefinitionByName() 创建对象。基本上,这里发生的事情是,你将取代对象 Object2的上面有你的类名。例如: game.terrain.Grass#20#450
  • 应用 X 和任何其他自定义属性上面创建你的对象。
  • 的对象添加到游戏
  • Use getDefinitionByName() to create your object. Basically what happens here is that you would replace object and object2 above with your class names. ie: game.terrain.Grass#20#450
  • Apply the x, y and any other custom properties to your object created above.
  • Add the object to the game

希望这有助于。如果没有,请考虑使用XML来创建一个类似于上述目的。

Hope this helps. If not, try looking at using XML to create objects similar to above.

另外,你可以看到这种方法在实践中看我的比赛在这里

Also, you can see this approach in practice by looking at my game here.

如果您使用的关卡编辑器,你就可以看到你的水平的数据在接近屏幕,这可能类似于此:

If you use the level editor, you'll be able to see your level data at the close screen, which may look similar to this:

2#36#20#o$t#12#12#w$t#12#16#w$t#12#24#w$t#12#28#w$t#12#20#w$g#20#11#o$1#24#21#o#200#110

在每个对象的第一个属性的说明,这其实再presents一个较大的字符串,以保持级别的数据结构紧凑,即:

A note on the first property of each object, this actually represents a larger string to keep level data compact, ie:

var shorthand:Object = {
    2: "game.objects.WoodenWall",
    g: "game.objects.Gate",
    t: "game.objects.Turret"
};

这篇关于什么是管理的flash游戏的游戏水平的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆