Jump to content

_tweens undefined on object


yougotashovel
 Share

Recommended Posts

I've been trying to extend the functionality of TweenManager, so it can resume and pause everything within a group.

 

I adapted the code from here:

http://jsfiddle.net/lewster32/L3u3gp5k/

http://docs.phaser.io/TweenManager.js.html#sunlight-1-line-127

 

When debugging with console, _tweens and _add are undefined for each object, so the function doesn't work.

 

I think the code is correct? Any ideas why this isn't working?  I'm guessing i've missed something crucial about _tweens.

 

 

Here's the code: (This goes out to Rich and Lewster)

Phaser.TweenManager.prototype.pauseAllFrom = function(obj, children) {console.log('pauseAllFrom', obj.type, obj.name, obj._tweens, obj._add);        var o, c, t, len;        if (Array.isArray(obj) ) {            for (o = 0, len = obj.length; o < len; o++) {                this.pauseFrom(obj[o]);               }        }        else if ( (obj.type === Phaser.GROUP || obj.type==7) && children){            for (c = 0, len = obj.children.length; c < len; c++){                this.pauseFrom(obj.children[c]);               }        }        else {            for (t = 0, len = this._tweens.length; t < len; t++){                if (obj === this._tweens[t]._object){                    console.log('pauseFrom _tweens:',this._tweens[t]);                    this._tweens[t].pause();                }            }            for (t = 0, len = this._add.length; t < len; t++){                if (obj === this._add[t]._object){                    console.log('pauseFrom _add:',this._add[t]);                    this._add[t].pause();                }            }        }};Phaser.TweenManager.prototype.resumeAllFrom = function(obj, children) {console.log('resumeAllFrom', obj.type, obj.name, obj._tweens, obj._add);        var o, c, t, len;        if (Array.isArray(obj) ) {            for (o = 0, len = obj.length; o < len; o++) {                this.pauseFrom(obj[o]);               }        }        else if ( (obj.type === Phaser.GROUP || obj.type==7) && children){            for (c = 0, len = obj.children.length; c < len; c++){                this.pauseFrom(obj.children[c]);               }        }        else {            for (t = 0, len = this._tweens.length; t < len; t++){                if (obj === this._tweens[t]._object){                    this._tweens[t].resume();                }            }            for (t = 0, len = this._add.length; t < len; t++){                if (obj === this._add[t]._object){                    this._add[t].resume();                }            }        }};

I also had to add a condition for the object type, as the console wasn't recognising Phaser.GROUP, and spitting out a number for each object type.

// from thiselse if (obj.type === Phaser.GROUP && children){// to thiselse if ( (obj.type === Phaser.GROUP || obj.type==7) && children){

Any help would be greatly appreciated.

Thanks

Link to comment
Share on other sites

Okay now i see that obj._tweens and obj._add don't exist.  And that the script is referencing 'this' as the TweenManager.

 

Still struggling to get it to work though.  I can get log information on everything in the script except inside this loop:

for (t = 0, len = this._tweens.length; t < len; t++){   if (obj === this._tweens[t]._object){      console.log(this._tweens[t);      this._tweens[t].pause();   }}
Link to comment
Share on other sites

Found one possible solution.

this._tweens[t]._object

Above doesn't appear to exist when passed into the console, but the below does, and works.

this._tweens[t].target

---

 

Anybody else who needs to pause tweens in a group or array, this code now works:

Phaser.TweenManager.prototype.pauseGroup = function(obj, children) {        var o, c, t, len;        if (Array.isArray(obj) ) {            for (o = 0, len = obj.length; o < len; o++) {                this.pauseFrom(obj[o]);               }        }        else if (Phaser.GROUP && children){            for (c = 0, len = obj.children.length; c < len; c++){                this.pauseFrom(obj.children[c]);               }        }        else {            for (t = 0, len = this._tweens.length; t < len; t++){                if (obj === this._tweens[t].target){                    this._tweens[t].pause();                }            }            for (t = 0, len = this._add.length; t < len; t++){                if (obj === this._add[t].target){                    this._add[t].pause();                }            }        }};

Then just call:

game.tweens.pauseGroup(group, true);

For some reason resume is kinda buggy, i couldn't get it to work.  If anybody figures out resume for groups, let me know.  game.tweens.resumeAll(); should do the trick for now though.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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