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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.