Colon

arcade.overlap callback to a function in an other file

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.