Jump to content

Sprite moves after resume a scene


Magali
 Share

Recommended Posts

Hi everyone! 

Everytime I resume my main scene, the main character keeps walking along and I can't control it with the keyboard. I think it's because remember the movement from before the scene was paused. I've tried everything, I set the velocity.x and velocity.y to 0 before pause the scene, create a variable isPaused and adapt the logict to that, but nothing works :(. Any idea? Thanks!

My code: 

 

        function workPopUp () {
            if(this.kid.body.velocity.x === 0){
                     this.scene.pause()
                     this.scene.launch('popup');
                     this.work.destroy();
                     this.physics.add.overlap(this.kid, this.diamondsPink, collectCeleste, null, this);     
            }
                
        }

and this is the update loop

        this.kid.body.velocity.x = 0      
  ``````if (this.cursorKeys.left.isDown){
               this.kid.setVelocityX(-200);
               this.kid.anims.play('left', true);
               
             }
        else if (this.cursorKeys.right.isDown){
                
                 this.kid.setVelocityX(200);
                 this.kid.anims.play('run', true);
            }
        else
             {
            this.kid.setVelocityX(0);
            this.kid.anims.play('idle', true);
            };

        if (this.cursorKeys.up.isDown && this.kid.body.touching.down)
        {
            
            this.kid.setVelocityY(-480);
        }

 

Link to comment
Share on other sites

  • 5 months later...

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