Jump to content

Effect for Item in a group


BrunoHautenfaust
 Share

Recommended Posts

Here's the problem. When player overlaps with an item from the group 'Items', the item should change its texture to a spritesheet animation. To indicate the item has been taken. However when the player takes 1 item, the rest(some or even most) change textures. And they don't meet the overlap condition.

game.physics.arcade.overlap(player, items, transformItem, null, this);

    transformItem: function(p, i) {
        i.loadTexture('sparkle', 0);
        i.animations.add('effect');
        i.animations.play('effect', 30, false);
        i.kill();
    };

So I tried this to restore the item texture: 

transformItem: function(p, i) {
    i.loadTexture('sparkle', 0);
    i.animations.add('effect');
    i.animations.play('effect', 30, false).onComplete.add(function() {
        i.kill();
        i.loadTexture('item');
    }, this);
};

This kind of works but not 100%. Because the animation takes time to complete, while it's playing other items might spawn with the 'sparkle' animation. Yet they don't meet the overlap condition.

Edit: Hmmm... now it seems to work without problems. That wasn't the case last night. Weird.

 

Link to comment
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...
 Share

  • Recently Browsing   0 members

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