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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...