【问题标题】:Update a scope variable value with Phaser and typescript in an ionic 2 app在 ionic 2 应用程序中使用 Phaser 和 typescript 更新范围变量值
【发布时间】:2017-09-11 15:47:52
【问题描述】:

我正在尝试使用 Ionic 2(使用 TypeScript)和 Phaser.io 创建一个游戏应用程序。到目前为止一切都很好,我的游戏可以正常运行,但是......

我可以在 TypeScript 函数中启动 Phaser 操作,但不能相反。

例如,我在我的 html 中由我的 TypeScript 控制器中的{{ score }} 定义了一个分数,我用this.score = 0; 初始化了这个分数,然后我可以在 TypeScript 函数中更新分数。但是在任何移相器功能(预加载、创建、更新、渲染)中,它都不再起作用了。下图中的示例(这是我的代码的类似简单版本)。

image example

谢谢。

【问题讨论】:

  • 您是否尝试注入 ChangeDetectionRef 然后调用 detectChanges()?
  • 对不起,我对此没有深入的了解......你有一个例子说明它是如何工作的吗?
  • 与其在代码中添加图像,不如将代码复制/粘贴到问题本身中。我也试图清理你的问题,但如果你能帮助澄清你在那里问的内容,你的第三段需要做更多的工作。

标签: typescript ionic-framework angularjs-scope ionic2 phaser-framework


【解决方案1】:

我对 Ionic 和 Phaser 组合相当陌生。据我了解,当我们这样做时

this.game = new Phaser.Game(width, height, renderer, parent, state, transparent, antialias, physicsConfig)

state 创建了一个新的范围(用于 Phaser),因此 Ionic 的 'ionViewDidEnter()' 和 Phaser 的 'create()' 中不会有相同的 'this'。 p>

我所做的(我不知道这是否是最好的解决方案)是添加

this.game = new Phaser.Game(width, height, renderer, parent, state)
this.game.ionic = this; // reference ionic Object to Phaser Object

现在我可以从 Phaser 内部调用 ionic

create() {
  this.game.ionic.alert.present();
}

【讨论】:

    猜你喜欢
    • 2018-02-10
    • 1970-01-01
    • 1970-01-01
    • 2018-04-27
    • 2016-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-03
    相关资源
    最近更新 更多