Jump to content

error when remove object when animation finished


lars
 Share

Recommended Posts

I have the following collide function in a class:

 

collide: function(opponent) {this.pumkins.textures=this.poffedPumkins.textures;this.pumkins.currentFrame=0;this.pumkins.loop=false; this.pumkins.onComplete = function(){this.remove();};}

I get the following error:

Cannot read property 'updateTransform' of undefined

on the this.remove();

 

It work allright when I call the this.remove() directly in the collide function. 

 

Link to comment
Share on other sites

Thank´s a lot for the answer 

 

Hhmmm. That did not do it :-)

 

Im a little bit confused about the bind method ... here is the class im working on. I would be very thankful if you have the time to have a look:

 

 
   game.createClass('Pumpkins', {        init: function() {               var myPumkingsVelocityArray=[100,80,60,50,40,32,45,67,78,98,90];         var pumkingVInterval = myPumkingsVelocityArray[Math.floor(Math.random()*myPumkingsVelocityArray.length)];                               var x = Math.random(16, game.system.width);                        //this.pumkins = new game.Sprite('pumkings');                         this.pumkins = new game.Animation('media/pumkings.png');             this.pumkins .animationSpeed = 0.3;             this.pumkins .position.set(230, 350);            this.pumkins.anchor.set(0,1);             this.pumkins.play();               this.poffedPumkins = new game.Animation(            'media/pum1.png',            'media/pum2.png',            'media/pum3.png',            'media/pum4.png',            'media/pum5.png'        );                                    this.pumkins.anchor.set(0.5, 0.5);            this.body = new game.Body({                position: {                    x: x ,                    y:  - this.pumkins.height                },                velocity: {                    x: 0,                    y: pumkingVInterval                },                collisionGroup: 1,                collideAgainst: [0],                mass: 0,                         });            this.body.collide = this.collide.bind(this);            this.body.addShape(new game.Rectangle(20, 20));            game.scene.addObject(this);            game.scene.world.addBody(this.body);            game.scene.stage.addChild(this.pumkins);            this.update();        },        collide: function() {          this.pumkins.textures=this.poffedPumkins.textures;this.pumkins.currentFrame=0;//In this case just run it oncethis.pumkins.loop=false;            //this.remove();            this.pumkins.onComplete(this.remove.bind(this));                         // this is the one i have been trying before                        /*              this.pumkins.onComplete = function(){                  this.remove();          };   */        },        update: function() {            this.pumkins.position.x = this.body.position.x;            this.pumkins.position.y = this.body.position.y;                        if (this.pumkins.position.y - this.pumkins.height / 2 > game.system.height) this.remove();            //this.body.position.x += 50 * game.system.delta;        },                 remove: function() {            game.scene.removeObject(this);            game.scene.world.removeBody(this.body);            game.scene.stage.removeChild(this.pumkins);        }    });
Link to comment
Share on other sites

Solution:

Adding a timer ... before remove ... found in Spaceshooter Example ... 

collide: function() {            this.pumkins.textures = this.poffedPumkins.textures;            this.pumkins.currentFrame = 0;            //In this case just run it once            this.pumkins.loop = false;            this.pumkins.onComplete = function() {                console.log("allo");          this.pumkins.visible = false;                            game.scene.addTimer(0, function() {              this.remove();}.bind(this));                                            }.bind(this);        },
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.

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

Loading...
 Share

  • Recently Browsing   0 members

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