Jump to content

help with uncaught typeError


ibb671
 Share

Recommended Posts

Hello I'm new to phaser and would like to ask for help. I am trying to make a matching game. Where if its not a match the sprite would reset to its position,disable drag and after 1 second to enable drag again. I used a timer and was getting this error Uncaught TypeError: Cannot read property 'apply' of undefined.

  update:function(){
      this.game.physics.arcade.overlap(this.playerGroup,this.imageGroup,this.checkCorrect,null,this);
      
  },
  checkCorrect:function(player,sprites){
    if(player.customParams==sprites.customParams){
      player.inputEnabled=false;
      player.kill();
      sprites.kill();
    }else{
      player.input.draggable = false;
      player.reset(player.OriginalX,player.OriginalY);
      this.game.time.events.add(1000,this.dragPlayer(player),this);
      
    }
    
      
  },
  
  dragPlayer:function(player){
    
    player.input.enableDrag()
  }

Thanks in advance

Screenshot 2016-06-02 at 5.24.13 PM.png

Link to comment
Share on other sites

The second parameter of time.events.add requires a function, but you are actually calling the function there on runtime which cause the time.events.add to call the result of this function, which is void. You can't apply on void (which is happening behind the scenes) so you need to do something like:

 

this.game.time.events.add(1000,function () {
    this.dragPlayer(player)
},this);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...