Jump to content

arcade.overlap callback to a function in an other file


Colon
 Share

Recommended Posts

Hi,
I am trying to organize my game, and try to collect some functions in an extra file so I dont need to rewrite them in every state. 

I am trying to convert this:
world.js

update: function() {        
        this.game.physics.arcade.overlap(this.player, this.items, this.collect, null, this);
        }

collect: function(player, collectable) {
        console.log('melon');
        collectable.destroy();
    },

to this:

world.js

update: function() {
        this.game.physics.arcade.overlap(this.player, this.items, collect(this.player, this.items), null, this);
}

functions.js

function collect(player, collectable) {
    console.log('melon');
    collectable.destroy();
}

 

So what happens when I run my game with that is that the collect function is in an infinite loop, even if I dont overlap the item. Can you tell my why it is doing that and how I can fix that?
Thanks,
Colon

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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