我写了游戏。它在运行程序时立即启动。一切工作在一个文档类中。现在,我想做一些基本的介绍,例如游戏开始前的动画倒计时。我怎么能暂停游戏?主时间轴上只有一帧包含背景。暂停游戏(ActionScript 3)
-1
A
回答
4
如果您的动画基于计时器。
当启动定时器:
timer.start();
last_time = getTimer();
时暂停计时器:
timer.stop();
pause_timer = getTimer() - last_time;
时恢复定时器:
last_time = getTimer();
timer.start();
希望,它会帮助你。
2
要添加到上面的Antony的答案,如果您使用事件侦听器来处理游戏循环操作,您可以简单地删除它们以暂停游戏,然后再次添加它们以重新启动它。例如:
package com.mygame.logic{
import flash.display.MovieClip;
import flash.display.Bitmap;
import fl.controls.Button; //to get this code to work you have to drag a UI component to your
//movie's library or Flash won't recognize it.
public class mygame extends MovieClip{ //this is to be the main document class for the .fla
private var bmp:Bitmap = new Bitmap(...); //fill in constructor with relevant data
private var myButton:Button = new Button();
private var paused:Boolean = false;
public mygame(){
bmp.x = 100;
bmp.y = 100;
myButton.x = 200;
myButton.y = 200;
this.addChild(bmp);
this.addChild(myButton);
this.addEventListener(Event.ENTER_FRAME, main);
myButton.addEventListener(MouseEvent.ON_CLICK, pause);
}
public function main(e:Event):void{
bmp.x += 1.0;
}
public function pause(e:MouseEvent):void{
if (!paused){
this.removeEventListener(Event.ENTER_FRAME, main);
this.paused = true;
}
else{
this.addEventListener(Event.ENTER_FRAME, main);
this.paused = false;
}
}
并且应该为基本的暂停功能做。你可以扩展上述做出一个很好的平视显示器用于命名和彩色按钮等用于暂停/重新启动游戏的玩家,使用补间来使HUD过渡到屏幕上很好...
希望它可以帮助, CCJ
相关问题
- 1. Flash - 暂停游戏ActionScript 3
- 2. 当游戏暂停时Phaser“暂停游戏”文本
- 3. scoreLabel.text使得游戏暂停
- 4. Actionscript 3重置游戏?
- 5. (AS3)Fixing Frogger游戏ActionScript 3
- 6. 暂停游戏循环?
- 7. clearInterval和暂停游戏
- 8. actionscript游戏
- 9. ActionScript 3中的游戏逻辑和游戏循环
- 10. ActionScript 3.拖放游戏出错
- 11. ActionScript 3的Flash游戏AI,路径或
- 12. 游戏解决方案ActionScript 3
- 13. Actionscript 3游戏:对象重生
- 14. ActionScript 3的过山车游戏
- 15. ActionScript 3制作游戏模式
- 16. 飞船测验游戏Actionscript 3
- 17. 游戏暂停/恢复功能
- 18. AIR to Android/OUYA的Flash游戏:暂停应用/游戏
- 19. 通过QML进入symbian^3主菜单暂停游戏
- 20. Javascript:暂停/暂停JavaScript俄罗斯方块游戏
- 21. 在通话过程中暂停游戏
- 22. 游戏c的暂停按钮#
- 23. 当进入背景时暂停游戏
- 24. 暂停屏幕设计的iOS游戏
- 25. Spritekit - 保持游戏暂停时didBecomeActive
- 26. 球拍暂停/继续按钮,游戏
- 27. 的cocos2d的Android不暂停游戏
- 28. 如何暂停和恢复andengine游戏?
- 29. 暂停后保存游戏状态。 AndEngine
- 30. 暂停或退出的的Android游戏
在游戏代码开始前放入一个计时器。在获得特定答案之前,您需要使用代码示例提出更详细的问题 – shanethehat
如何让文档类在第二个或其他框架上启动? – nicks
你不知道。您不必让代码开始游戏,而是让代码启动您的计时器动画,并在游戏完成时才开始游戏。如果你发布你的代码,也许你会得到一个更清晰的答案。 – shanethehat