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

 Share

  • Recently Browsing   0 members

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