nak3ddogs Posted July 3, 2014 Share Posted July 3, 2014 helo. Im rly newby in phaser and have lots of question. first of all. the tween in my funtion make a rly freak bug. when the bullet arrive the goal, turn back and go straight left.i wanna make this bullet slowing down and stop at the end of the tween.2. question: can i have a better solution for animate the bullet? thx for any advice and sry for my dumb questions function update() { if (cursors.down.isDown && timerFire == 0){ console.log('pina'); timerFire = 20; var penz = bullets.getFirstExists(false); penz.timeLeft = 300; penz.animations.add('loopedCoin', [ 7, 6, 5, 4, 3, 2, 1, 0], 10, true); penz.animations.play('loopedCoin'); if (facing === 'right') { penz.reset(player.x +10, player.y ); penz.body.velocity.y=-200; // penz.body.velocity.x=200; game.add.tween(penz).to({ x: player.x+250 }, 2000, Phaser.Easing.Out, true); } else { penz.reset(player.x -10, player.y); penz.body.velocity.y=-200; penz.body.velocity.x=-200; } } Link to comment Share on other sites More sharing options...
lewster32 Posted July 3, 2014 Share Posted July 3, 2014 The slowing down and stopping stuff is done via the easing; take a look at this example to see how the different easing functions look: http://gamemechanicexplorer.com/#easing-1 I suspect the reason your bullet is going back the other way is that the velocity is still in effect. Your tween temporarily overrides the velocity by forcibly positioning your bullet, but as soon as the tween ends any velocity that was previously applied is instantly re-applied. Additionally you shouldn't mix velocity-based movement with tweening without setting sprite.body.moves = false during the tween to ensure you don't get jittery movement or other weird things happening, because otherwise you have the physics system and the tween fighting over who gets to move the sprite. Link to comment Share on other sites More sharing options...
Recommended Posts