JS开发HTML5游戏《悠悠考拉》(三)

                                        (点击图片可进入试玩)

本篇文章为第三部分内容,这篇文章将接着上篇文章的内容,这篇文章的主要内容有:

7、游戏中的暂停与结束处理

8、排行榜界面

 

七、游戏中的暂停与结束处理

7.1 暂停

暂停处理:在游戏中,秋千的摇摆、柱子的移动等都是通过Tween动画实现的,例如秋千摇摆我们可以加TweenRation动画、柱子移动可以加TweenPosition动画。当我们按下暂停键时,此时,秋千与柱子还有考拉等应该是静止的,我还希望能弹出另一个界面,该界面有一些界面按钮,点击按钮可以实现对应的操作,关闭弹出的界面时,我们又可以继续游戏。首先我们可以在Main.js中加入代码对暂停按钮进行监听点击事件:代码如下,

 1 var Main = qc.defineBehaviour('qc.Koala.ui.Main', qc.Behaviour, function() {
 2     // 风值
 3     this.windValue = 0;
 4 
 5     // 掉落事件控制器
 6     this.dropTimer = null;
 7 
 8     // 跳台对象
 9     this._step = null;
10 
11     // 秋千对象
12     this.swing = null;
13 }, {
14     // 柱子池
15     pillarPool : qc.Serializer.NODE,
16     // 考拉节点
17     koala : qc.Serializer.NODE,
18     // 暂停按钮
19     pauseBtn : qc.Serializer.NODE,
20     // 风值
21     wind : qc.Serializer.NODE,
22     // 风向
23     windDirection : qc.Serializer.NODE,
24     // 分数节点
25     score : qc.Serializer.NODE
26 });
27 /**
28  * 初始化
29  */
30 Main.prototype.awake = function() {
31     var self = this;
32 
33     // 监听暂停按钮点击事件
34     this.addListener(this.pauseBtn.onClick, this._pause, this);
35 
36     // 继续游戏时,恢复暂停按钮交互
37     this.addListener(qc.Koala.onContinue, function() {
38         this.pauseBtn.interactive = true;
39     }, this);
40 };
41 /**
42  * 暂停游戏
43  */
44 Main.prototype._pause = function () {
45     // 如果游戏结束,则暂停按钮点击不做任何处理
46     if (qc.Koala.logic.me.isDie)
47         return;
48 
49     // 设置游戏暂停状态
50     qc.Koala.logic.me.paused = true;
51 
52     // 派发游戏暂停事件
53     qc.Koala.onPause.dispatch();
54 };
View Code

相关文章:

  • 2022-01-20
  • 2022-01-17
  • 2021-05-14
  • 2021-09-17
  • 2021-06-23
  • 2021-12-02
  • 2021-07-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-19
  • 2021-10-18
  • 2021-11-23
  • 2021-09-09
  • 2021-12-15
相关资源
相似解决方案