Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ionic 2应用程序中使用Phaser和typescript更新范围变量值_Typescript_Ionic Framework_Angularjs Scope_Ionic2_Phaser Framework - Fatal编程技术网

在ionic 2应用程序中使用Phaser和typescript更新范围变量值

在ionic 2应用程序中使用Phaser和typescript更新范围变量值,typescript,ionic-framework,angularjs-scope,ionic2,phaser-framework,Typescript,Ionic Framework,Angularjs Scope,Ionic2,Phaser Framework,我正在尝试用Ionic 2(使用TypeScript)和Phaser.io创建一个游戏应用程序。到目前为止一切都很好,我的游戏也很好,但是 我可以在TypeScript函数中启动Phaser操作,但我不能做相反的事情 例如,我在html中定义了一个分数,该分数由我的TypeScript控制器中的{{score}定义,我使用this.score=0初始化该分数然后我可以在TypeScript函数中更新分数。但是在任何相位器函数(预加载、创建、更新、渲染)中,它不再工作。下图中的示例(类似于我的代码

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

我可以在TypeScript函数中启动Phaser操作,但我不能做相反的事情

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


谢谢。

我对爱奥尼亚和移相器组合相当陌生。据我所知,当我们

this.game = new Phaser.Game(width, height, renderer, parent, state, transparent, antialias, physicsConfig)
状态为Phaser创建了一个新的作用域,因此在Ionic的“IonViewDiCenter()”和Phaser的“create()”中不会有相同的“this”

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

this.game = new Phaser.Game(width, height, renderer, parent, state)
this.game.ionic = this; // reference ionic Object to Phaser Object
现在我可以从内部相位器调用离子

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

我对爱奥尼亚和移相器组合相当陌生。据我所知,当我们

this.game = new Phaser.Game(width, height, renderer, parent, state, transparent, antialias, physicsConfig)
状态为Phaser创建了一个新的作用域,因此在Ionic的“IonViewDiCenter()”和Phaser的“create()”中不会有相同的“this”

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

this.game = new Phaser.Game(width, height, renderer, parent, state)
this.game.ionic = this; // reference ionic Object to Phaser Object
现在我可以从内部相位器调用离子

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

您是否尝试注入ChangeDetectionRef,然后调用detectChanges()?很抱歉,我对此不太了解。。。你有这样的例子吗?与其在代码中添加图像,不如将代码复制/粘贴到问题本身中。我还试图澄清你的问题,但如果你能帮助澄清你的问题,你的第三段需要做更多的工作。你是否尝试注入ChangeDetectionRef,然后调用detectChanges()?对不起,我对此不太了解。。。你有这样的例子吗?与其在代码中添加图像,不如将代码复制/粘贴到问题本身中。我也试图澄清你的问题,但如果你能帮助澄清你的问题,你的第三段需要做更多的工作。