Jump to content

PHASER : Chained transitions issue


Le Sparte
 Share

Recommended Posts

Hi there,

Hi have a sprite moving on the x axis at a given speed. When the user press on the space bar, I want (1) the sprite to stop on y axis, (2) make a move to the right, (3) go back at his initial position, and (4) continue his way on y.

I've tried with the following code but the sprite stops while going back to his position and keeps shaking. Is there an easier way to do what I'm trying to achieve? If not, how could I debug this code?

Many thanks!

PS: my sprite will have to consider collisions.


	    if (this.space.isDown){
        let position_man = this.man.body.y;
        let speed_man = this.man.body.velocity.y;
        this.man.body.velocity.y = 0;
        let tween = game.add.tween(this.man);
        tween.to({x:200},100,"Quart.easeOut");
        tween.start();
        tween.onComplete.addOnce(retour,this);
        
        function retour(){
            let tween2 = game.add.tween(this.man);
            tween2.to({x:100},100,"Quart.easeOut");
            tween2.start();      
        }
        this.man.body.velocity.y = speed_man;

 

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