difenduandada
2024-12-31 34abe6963b344c882358274957f4b992456fee40
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
49
50
51
52
53
54
55
56
57
58
59
var _frameRate = 60;
cc.game.setFrameRate = function (frameRate) {
    _frameRate = frameRate;
    if (wx.setPreferredFramesPerSecond) {
        wx.setPreferredFramesPerSecond(frameRate);
    }
    else {
        if (this._intervalId) {
            window.cancelAnimFrame(this._intervalId);
        }
        this._intervalId = 0;
        this._paused = true;
        this._setAnimFrame();
        this._runMainLoop();
    }
};
 
cc.game._setAnimFrame = function () {
    this._lastTime = performance.now();
    this._frameTime = 1000 / _frameRate;
 
    if (_frameRate !== 60 && _frameRate !== 30) {
        window.requestAnimFrame = this._stTime;
        window.cancelAnimFrame = this._ctTime;
    }
    else {
        window.requestAnimFrame = window.requestAnimationFrame || this._stTime;
        window.cancelAnimFrame = window.cancelAnimationFrame || this._ctTime;
    }
};
 
cc.game.getFrameRate = function () {
    return _frameRate;
};
 
cc.game._runMainLoop = function () {
    var self = this, callback, config = self.config,
        director = cc.director,
        skip = true, frameRate = config.frameRate;
 
    cc.debug.setDisplayStats(config.showFPS);
 
    callback = function () {
        if (!self._paused) {
            self._intervalId = window.requestAnimFrame(callback);
            if (frameRate === 30) {
                if (skip = !skip) {
                    return;
                }
            }
            director.mainLoop();
        }
    };
 
    self._intervalId = window.requestAnimFrame(callback);
    self._paused = false;
};
// wechat game platform not support this api
cc.game.end = function () {};