美文网首页
(1) 游戏生命周期

(1) 游戏生命周期

作者: Heartcase_b8c0 | 来源:发表于2020-08-23 11:02 被阅读0次

探究游戏生命周期

程序入口

  const main = new Main();
  main.run();

主线: 程序入口 Main

// in Main.prototype.run
showLoadingSpinner();
testXhr();
loadMainScripts(); // ※ 异步执行, 加载RM脚本

// 异步回调
// in Main.prototype.onWindowLoad
initEffekseerRuntime() // 异步执行

// 这期间发生了各个RM脚本的加载

// 异步回调 (当所有脚本初始化完毕)
// in Main.prototype.onEffekseerLoad
SceneManager.run(Scene_Boot); // ※ SceneManager启动

主线: SceneManager 初始化

SceneManager.run = function(sceneClass) {
    try {
        this.initialize(); // ※ 执行各种初始化
        this.goto(sceneClass);
        Graphics.startGameLoop(); // ※ 启动PIXI.Application 见下文
    } catch (e) {
        this.catchException(e);
    }
};

// 初始化函数, 省略部分代码
SceneManager.initialize = function() {
    this.initGraphics(); // ※ 初始化图像
};

// 初始化图像
SceneManager.initGraphics = function() {
    // ※ 初始化Graphics静态类, 包括PIXI对象, 见下文
    if (!Graphics.initialize()) {
        throw new Error("Failed to initialize graphics.");
    }
    // ※ 绑定SceneManager的update到PIXI的ticker上面
    Graphics.setTickHandler(this.update.bind(this));
};

支线: PIXI.Ticker 初始化

// Graphics静态类初始化, 省略部分代码
Graphics.initialize = function() {
  this._tickHandler = null;
  this._app = null;
  this._createPixiApp();
}

// 初始化PIXI.Application
Graphics._createPixiApp = function() {
    try {
        this._setupPixi();
        this._app = new PIXI.Application({
            view: this._canvas,
            // ※ ticker 默认是停止状态
            autoStart: false
        });
        // 使用了默认的公用计时器:PIXI.Ticker.shared
        // 移除默认render
        this._app.ticker.remove(this._app.render, this._app);
        // ※ 绑定_onTick事件, 等价于绑定_tickHandler, 等价于绑定SceneManager.update
        this._app.ticker.add(this._onTick, this);
    } catch (e) {
        this._app = null;
    }
};

// 包含了帧数修正的_onTick方法
// Ticker的默认FPS是60
Graphics._onTick = function(deltaTime) {
    this._fpsCounter.startTick();
    if (this._tickHandler) {
        this._tickHandler(deltaTime);
    }
    if (this._canRender()) {
        this._app.render();
    }
    this._fpsCounter.endTick();
};

支线: PIXI.Ticker 启动

// 在 SceneManager.run中
Graphics.startGameLoop()

// 计时器启动, 周期性触发SceneManger.update, 从而更新整个游戏画面
Graphics.startGameLoop = function() {
    if (this._app) {
        this._app.start();
    }
};

总结

image.png

相关文章

  • (1) 游戏生命周期

    探究游戏生命周期 程序入口 主线: 程序入口 Main 主线: SceneManager 初始化 支线: PIXI...

  • Unity开发-生命周期函数

    1、生命周期函数 废话不说直接代码演示 2、各个生命周期函数的作用 1.Awake:用于在游戏开始之前初始化变量或...

  • 20180725游戏运营

    1.什么是游戏运营 从定义上,游戏运营是在游戏的整个生命周期里,把一款游戏推上线,有计划地实施产品运作策略和营销手...

  • 《资本游戏》(1):企业生命周期

    最接近人性的游戏——资本游戏 2013年,国家工商总局发布过一份《全国内资企业生存时间分析报告》,报告数据显示,在...

  • 大连滕泰科技学习笔记2020-07-21

    1,上午 1,1 maven生命周期-- clean生命周期-- default生命周期-- site生命周...

  • (五)游戏生命周期回调

    (五)游戏生命周期回调 Cocos Creator Cocos Creator 为组件脚本提供了生命周期的回调函数...

  • 什么是LTV

    生命周期(Life time):一个用户从第一次参与游戏,到最后一次参与游戏之间的时间。一般算平均时间。生命周期价...

  • 游戏运营的思维清单

    1.游戏的基因,很可能决定了一个游戏的生命周期,例如moba王者荣耀,Rpg仙剑奇侠传,不同群体会有不同的瓶颈期。...

  • Unity游戏开发核心:生命周期

    Unity游戏开发中的生命周期 C#对象的生命周期 生命周期是Unity开发过程中的核心思想,是技术进阶过程中必须...

  • 游戏指标分析之----LTV

    定义 LTV:Life Time Value 用户生命周期价值,用户在生命周期内为该游戏创造的收入总和。可以看作了...

网友评论

      本文标题:(1) 游戏生命周期

      本文链接:https://www.haomeiwen.com/subject/acjijktx.html