Jump to content

Simple tween not working


kriket
 Share

Recommended Posts

I am trying to make a simple tween work but for some reason, its not working. I dont get any errors. Tweens just arent working at all. 

  create: function() {    this.game.physics.startSystem(Phaser.Physics.P2JS);    this.game.physics.p2.setImpactEvents(true);    this.game.physics.p2.restitution = 0.5;    this.game.physics.p2.gravity.y = 300;    this.playerCollisionGroup = this.game.physics.p2.createCollisionGroup();    this.cloudsCollisionGroup = this.game.physics.p2.createCollisionGroup();    //  Platforms that move    this.clouds = this.game.add.group();    this.clouds.enableBody = true;    this.clouds.physicsBodyType = Phaser.Physics.P2JS;    var cloudArray = [];    for(var i = 0; i < 3; i++){            cloudArray[i] = this.clouds.create(400*i, 350*i, 'cloud-platform');            cloudArray[i].body.kinematic = true;            cloudArray[i].body.data.gravityScale = 0;            cloudArray[i].body.setCollisionGroup(this.cloudsCollisionGroup);            cloudArray[i].body.collides([this.cloudsCollisionGroup, this.playerCollisionGroup]);      }//    this.liftTween1 = this.add.tween(this.clouds.getAt(0)).to( { x: 1000 }, 2000, "Linear", true, 0, -1, true);  //    this.liftTween2 = this.add.tween(this.clouds.getAt(1)).to( { x: 1000 }, 2000, "Linear", true, 0, -1, true);      this.liftTween1 = this.add.tween(cloudArray[0]).to( { x: 1000 }, 2000, "Linear", true, 0, -1, true);      this.liftTween2 = this.add.tween(cloudArray[1]).to( { x: 1000 }, 2000, "Linear", true, 0, -1, true);      this.liftTween1.start();    this.liftTween2.start();        },
    
 
So you can open in Brackets and run it. 
Link to comment
Share on other sites

You can't change positions or angles for sprite with enabled physics bodies.

 

Actually tweens are applied to them but we can't see it because it is "overriden" by physics later in update loop.

 

Move bodies by applying velocity or impulse.

Link to comment
Share on other sites

Shouldn't you write this.game.add.tween... ?

 

Not necessary. Although, did try it just to be sure and still doesnt work. FWIW, in a previous game I did tween using this.add.tween so that shouldnt be the problem.

 

Make the clouds immovable.

 

I am using p2 not arcade, icp. So already had clouds set to immovable using both lines listed below

            cloudArray[i].body.kinematic = true;//            cloudArray[i].body.static = true;
And still tweens dont work.
Link to comment
Share on other sites

What if you animate cloudArray[0].body instead? Also, check the parameters of the tween.

 

 

YOU LEGEND!!!

 

    this.liftTween1 = this.add.tween(cloudArray[0].body).to( { x: 1000 }, 2000, "Linear", true, 0, -1, true);  

This works!!!

 

How can I thank you guys. Without all your support, this game would not have been possible. Trust me its coming out soon, and hopefully by the end of it, I would have mastered phaser. 

 

Just a couple more behaviours to add and voila, we will have something to play with! Artwork is done already!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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