Jump to content

tween.onComplete only works on last child of group


Recommended Posts

 for (var i = 0; i < enemies.length; i++) {
            var e = enemies.getChildAt(i);
            if (e.isTweening) {
            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

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.

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.


  • Recently Browsing   0 members

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