/
PauseScene.js
48 lines (41 loc) · 1.31 KB
/
PauseScene.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
define(['cocos2d'], function (cc) {
'use strict';
var PauseScene = cc.Layer.extend({
init:function () {
var winSize = cc.Director.sharedDirector().getWinSize();
var label = cc.LabelTTF.create('Click to unpause', 'Press Start 2P', 20);
label.setPosition(winSize.width / 2, winSize.height / 2);
this.addChild(label);
return true;
},
onEnter: function() {
this._super();
cc.sharedEngine.stopAllEffects();
if (cc.sharedEngine.isBackgroundMusicPlaying()) {
cc.sharedEngine.pauseBackgroundMusic();
this.restoreMusic = true;
}
},
onExit: function() {
this._super();
cc.sharedEngine.resumeAllEffects();
if (this.restoreMusic) {
cc.sharedEngine.resumeBackgroundMusic();
}
}
});
PauseScene.node = function () {
var node = new PauseScene();
if (node && node.init()) {
return node;
}
throw new Error('Unable to initialize node');
};
PauseScene.create = function () {
var scene = cc.Scene.create();
scene.addChild(this.node());
scene.isPause = true;
return scene;
};
return PauseScene;
});