tomhar Posted February 19, 2015 Share Posted February 19, 2015 Hi Guys, I have a little problem with player.body movement with constant factor.I got only three requirements: 1. When event occurs (ex. click on button) - player will change position by ex. 100 px, 2. But this position will be changed smoothly (I mean, walk should be visible, so implementation will be placed in update(), right? ) 3. Collisions My implementation is a bit strange, but work as well... with small precision. I've created timer, which starts counting down time when event occurs. During counting down, player is moving in desired direction. When counting is finished, I've call a function which stops movement. It's not a good idea, because precision varies about ~10-20px.Code with comments (only necessary lines, so dont worry about syntax errors ): oncreate() { var right = false; button = game.add.button(750, 500, 'button', ActionForMove, this, 2, 1, 0);[...]function ActionForMove() { //here is lots of cases in switch case 'Up': game.time.events.add(Phaser.Timer.SECOND*step, setFalse, game); // start count down up = true; // start moving in oncreate function break;}function setFalse(){ up = false; // when counting finish, player stops moving} function update() {if(up) { player.body.velocity.y=-100; } I would be very grateful if You got some solutions, or advices.Regards, Link to comment Share on other sites More sharing options...
Recommended Posts