Jump to content

tween.onComplete only works on last child of group


SolitudeX
 Share

Recommended Posts

 for (var i = 0; i < enemies.length; i++) {
            var e = enemies.getChildAt(i);
            if (e.isTweening) {
                continue;
            }
            e.isTweening = true;
            var r = game.rnd.between(100, 200);
            var a = game.rnd.between(0, 2 * Math.PI);
            var x1 = e.x + r * Math.cos(a);
            var y1 = e.y + r * Math.sin(a);
            var tween = game.add.tween(e).to(
                { x: x1, y: y1 }, 10 * r, null, true, 0, 0, false
            );
            tween.onComplete.add(function () {
                console.log("complete. e.isTweening:"+e.isTweening+" e.name:"+e.name);
                e.isTweening = false;
            });
}

The code above is in update,I want all the enemies to move randomly.

 I added name and isTweening to Sprite.prototype.

But the problem is only the last child of the group runs the onComplete function . In the log the e.name is always the last child of the group.

What wrong wrong with my code?

Thanks a lot for your answer~

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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