kriket Posted August 12, 2015 Share Posted August 12, 2015 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(); }, Project here, https://www.dropbox.com/sh/s7kyfscid7no6r7/AAC89QdMuGqVuTb8s2b92sDza?dl=0So you can open in Brackets and run it. Link to comment Share on other sites More sharing options...
qdrj Posted August 12, 2015 Share Posted August 12, 2015 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 More sharing options...
kriket Posted August 12, 2015 Author Share Posted August 12, 2015 But its done here in the official tutorial. http://phaser.io/tutorials/coding-tips-004 Link to comment Share on other sites More sharing options...
icp Posted August 12, 2015 Share Posted August 12, 2015 Make the clouds immovable. Link to comment Share on other sites More sharing options...
Skeptron Posted August 12, 2015 Share Posted August 12, 2015 Shouldn't you write this.game.add.tween... ? Link to comment Share on other sites More sharing options...
kriket Posted August 12, 2015 Author Share Posted August 12, 2015 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 More sharing options...
Skeptron Posted August 12, 2015 Share Posted August 12, 2015 Can you make a JSFiddle of it? Would be easier for us to test rather than guess Link to comment Share on other sites More sharing options...
qdrj Posted August 12, 2015 Share Posted August 12, 2015 But its done here in the official tutorial. http://phaser.io/tutorials/coding-tips-004Maybe you should use addMotionPath instead of manually creating tweens. Thats how it is done in this tutorial. Link to comment Share on other sites More sharing options...
tips4design Posted August 12, 2015 Share Posted August 12, 2015 What if you animate cloudArray[0].body instead? Also, check the parameters of the tween. kriket 1 Link to comment Share on other sites More sharing options...
kriket Posted August 12, 2015 Author Share Posted August 12, 2015 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! drhayes 1 Link to comment Share on other sites More sharing options...
Recommended Posts