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


  • Recently Browsing   0 members

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