title: ANGULAR AND PHASER CE How call Angular function in Phaser CE update function
body: <p>I need call a function that trow a modal created with NgbModal. In the <strong>update()</strong> function, managed by Phaser CE, When the condition is true, the app crash throwing this: <strong>ERROR TypeError: this.gameOver is not a function</strong> I've tested all. gameOver() function exit from class, but the modalService created in the constructor is undefined....</p>
  <p>Someone can help me?</p>
  <p>mi ts File:</p>
  <pre><code>@ViewChild('msgGameOver') public modalmsgGameOver:TemplateRef&lt;any&gt;;
  
  constructor( public modalService: NgbModal, private router:Router, private storage:Storage, 
  private endpoint:EndpointsService){}
  
  ngOnInit(){
    
  game = new Phaser.Game(
    window.innerWidth, window.innerHeight,
    Phaser.AUTO, 
    'garrioCatapulta',
    {preload: this.preload, create: this.create, update: this.update, render: this.render},
    true
  );
  
  that = Object.create(this.constructor.prototype);    
  }
  
  gameOver() {
  this.msgGameOver = &quot;lo sentimos, no has acertado la casilla ganadora&quot;
  this.headerGameOver=&quot;¡Has perdido!&quot;;
  this.iconGameOver = &quot;assets/error.svg&quot;;
  this.modalService.open(this.modalmsgGameOver);
  }
  
  preload(){
  
    game.load.image('roca', 'assets/aislada.svg');
    game.load.image('rebote','assets/rebote.svg');
    game.load.image('catapulta-dispara','assets/componentes_juego_catapulta_disparo.svg');
    game.load.image('colina', 'assets/derecha.svg');
    game.load.image('castillo', 'assets/izquierda_castillo.svg');
    
  }
  create(){
  
    game.scale.scaleMode = Phaser.ScaleManager.EXACT_FIT;     
    game.scale.pageAlignHorizontally = true;      
    game.scale.pageAlignVertically = true;        
  
    game.scale.refresh();
  
    game.physics.startSystem(Phaser.Physics.ARCADE);
  
    roca = game.add.sprite(200, 500, 'roca');
    castillo = game.add.sprite(0,350,'castillo');
    catapulta=game.add.sprite(300,525,'catapulta-dispara');
    
    colina = game.add.sprite(280,565,'colina');
    colina.alignIn(game.world.bounds, Phaser.BOTTOM_RIGHT);
    catapulta.alignTo(colina,Phaser.TOP_LEFT);
    roca.alignTo(catapulta,Phaser.TOP_RIGHT);
  
    game.physics.enable(roca, Phaser.Physics.ARCADE);
    game.physics.enable(colina, Phaser.Physics.ARCADE);
    game.physics.enable(catapulta, Phaser.Physics.ARCADE);
    game.physics.enable(castillo, Phaser.Physics.ARCADE);
  
    obstaculos = game.add.group()
    obstaculos.enableBody = true;
  
    colina.body.immovable = true;
    castillo.body.immovable = true;
  
    colina.body.immovable = true;
    castillo.body.immovable = true;
    catapulta.body.immovable = true;
  
    for (var i = 0; i &lt; 3; i++)
    {
  
        var s = obstaculos.create(game.rnd.integerInRange(75, 270),game.rnd.integerInRange(250, 500), 'rebote');
        s.body.collideWorldBounds = true;
        s.body.immovable = true;
        s.body.bounce.set(0.2);
    }
  
  }
  
  
  
  update(){
    
    if(game.physics.arcade.collide(roca, obstaculos)){
      console.log(&quot;choca roca&quot;)
    }
    
    if(game.physics.arcade.collide(roca, castillo)){
      c++;
      if(c &gt;= 20){
        roca.body.stop();
        console.log(&quot;A pis pos&quot;);
        game.paused=true;
        this.gameOver();
      }
    }
  
    if(game.physics.arcade.collide(roca, colina)){
      co++;
      if(co &gt;= 20){
        roca.body.stop();
        console.log(&quot;A pis pos&quot;);
        game.paused=true;
        this.gameOver();
      }
    };
  
    if(roca.body.onFloor()){
      i++;
      if(i &gt;= 20){
        roca.body.stop();
        console.log(&quot;A pis pos&quot;);
        game.paused=true;
  
        this.gameOver();
      }
    }
  
  }
  
  render() { 
  
  }
  </code></pre>
  <p>}</p>