I am using ionic framework to develop my Game.
I used Phaser as a plugin. Everything is going well but I am not able to use any external variable inside my game.
For example the highest score. I want to show it in my app menu.
I already tried:
this.game.global={ ... };
By refering this : http://www.html5gamedevs.com/topic/21143-global-variables/ but its showing compiletion error.
Please help
Edit: sample Code:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams,Platform } from 'ionic-angular';
import "pixi";
import "p2";
import * as Phaser from "phaser-ce";
import {GlobalvarProvider} from '../../providers/globalvar/globalvar';
import { create } from 'domain';
@IonicPage()
@Component({
selector: 'page-game',
templateUrl: 'game.html',
})
export class GamePage {
width:any=0;
height:any=0;
game: Phaser.Game;
heightscore:any;
constructor(
public navCtrl: NavController
, platform: Platform
,public gvp:GlobalvarProvider
) {
this.heightscore= this.gvp.highscore; // here I am able to assign value from the gvp:GlobalvarProvider
this.width=platform.width();
this.height=platform.height();
this.totalscore = 0;
this.game = new Phaser.Game(this.width, this.height, Phaser.CANVAS, 'phaser-example'
, { create: this.create,preload:this.preload,update:this.update
});
}
preload () {
this.heightscore = this.gvp.highscore;
// Problem is here. here I am not able to assign value from the GlobalvarProvider.
// also the value which I assined earlyer inside the constructor is not showing.
//I tried this.game.global={ this.heightscore = this.gvp.highscore; }; which is not working
}
create() {
...
}
update(){
...
}