Jump to content

Async forEachSeries on Tweens


Recommended Posts

This is my async.forEachSeries function:

async.forEachSeries(parsed.moves,function(move, callback) {
                that.moveObj(move, callback)
            }, function() {
                console.log('done running the entire code')

Move object is starting the tween and calling the callback onComplete of the tween.

moveObject(x, y, obj,callbackToAsync, offsetX = 0, offsetY = 0) {

  let coordinates = this.convert(obj.i + offsetX,obj.j + offsetY)
  let tween = this.game.add.tween(obj, this.game, this.game.tweens).to({
    x: coordinates.x,
    y: coordinates.y
  }, 2000)


So from my understanding, each move should be called and after the tween for that move is complete it should call the callback and proceed to the next iteration with the next move in the array.

What ends up happening is that the first move is executed and then it goes to the function that should be called when all iterations are done without completing all the iterations. I've made sure that the moves array has more than one object.

So this has something to do with the tween, since when I simply call the callback in moveOb it processes the moves sequentially.

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...