卸载内容 - 主菜单 Actionscript 3

发布于 2024-10-28 08:13:02 字数 145 浏览 1 评论 0原文

我是 Flash ActionScript 3 的新手,正在尝试学习。我制作了一个简单的菜单,其中有“开始游戏”选项。当用户按下“开始游戏”时,我隐藏菜单,游戏开始。现在,如果我想“退出”并进入菜单屏幕,我该怎么做?如何删除/停止用户刚刚玩的游戏?感谢您对此事的任何帮助^^。

i am new to flash actionscript 3 and trying to learn. I have a made a simple menu that has "start game" option. When the uses preses "start game", i hide the menu and the game starts. Now if i want to go "quit" and go the menu screen, how can i do this? How do i erase/stop the game that the user just played? thanks for any help on this matter ^^.

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

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

发布评论

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

评论(1

别低头,皇冠会掉 2024-11-04 08:13:02

如果您在时间轴上编码,最简单的方法是将游戏(图形、代码等)放置在其自己的 MovieClip 中,而不是放在主时间轴上。然后,您可以在游戏完成时从舞台上删除该包装器 MovieClip,方法是跳转到该 MovieClip 不存在的帧,或者使用 removeChild 在您的代码中。

如果您使用类文件,概念是相同的:将游戏放入其自己的剪辑中。在这种情况下,您的游戏将自然地包装在自己的剪辑中,因为它将是一个 Sprite:class Game extends Sprite。但是,您不想使用 Game 作为 Document 类,而是希望使用如下代码创建它并将其添加到舞台:

var game:Game = new Game();
addChild(game);

类似地,您可以在游戏完成时使用 removeChild(game) 从舞台中删除 Game 实例;

这会在游戏结束时删除游戏显示。不过,最重要的部分是,您必须删除 ENTER_FRAMEKEY_DOWN 以及您的游戏可能创建的任何其他侦听器。即使您将游戏从舞台上移除,这些 ENTER_FRAME 处理程序也将继续运行(可能无限期地运行)。这通常会导致错误和性能问题,因为即使您希望游戏停止,游戏也会继续运行。因此,当游戏结束时,首先使用 removeEventListener。 (如果您可以将游戏限制为尽可能少的 ENTER_FRAME 侦听器,这也会很有帮助,这样这一步就很容易。)然后就可以安全地从舞台上删除游戏剪辑了。

If you are coding on the timeline, the easiest way is to place your game (graphics, code, etc.) inside its own MovieClip, as opposed to on the main timeline. Then you can remove that wrapper MovieClip from the stage when the game is complete, either by jumping to a frame where that MovieClip doesn't exist, or by using removeChild in your code.

If you are using class file(s), the concept is the same: Put the game inside its own clip. In this case, your game would be wrapped in its own clip naturally because it would be a Sprite: class Game extends Sprite. But instead of using Game as the Document class, you want to create and add it to stage using code like the following:

var game:Game = new Game();
addChild(game);

Similarly, you can just remove your Game instance from the stage when the game is done using removeChild(game);.

This takes care of removing the game display when the game is over. The most important part, though, is that you must remove ENTER_FRAME, KEY_DOWN and any other listeners your game may have created. Even when you remove your game from the stage, these ENTER_FRAME handlers will continue to run (possibly indefinitely). This will often cause errors and performance problems because the game continues running even though you want it to stop. Therefore, when the game ends, first remove these event listeners using removeEventListener. (It's also helpful if you can limit your game to as few ENTER_FRAME listeners as possible, so that this step is easy.) Then it's safe to remove the game clip from the stage.

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