Temporarily stop the player for a couple of seconds

I want to temporarily stop the player from moving for a couple of seconds after it collides with an item in the game. I’ve added a function in a
player class for that purpose and managed to disable the controls, but the player keeps moving after the collision.

Here is the function I wrote:

specialItemCollected()
	{
		
		
		this.scene.input.keyboard.enabled = false
		
		this.scene.time.delayedCall(2000, () => {
			this.scene.input.keyboard.enabled = true
		  }, [], this);

	}

The pictures illustrate the effect I want to achieve:

c6bcf0194d7c86284d5067429fc9a3d8430c017e_hq

Hi

Try this syntax:

this.scene.time.addEvent({
  delay: 2000,
  callback: () => {
    this.scene.input.keyboard.enabled = true
  }
});

No that didn’t work. The player keeps moving even though I release the arrow key after the collision :upside_down_face:

However, I solved it by adding a boolean variable called isPlayerMovable which by default is true:

foundItem()
	{
		
		this.isPlayerMovable = false
		
			
		this.scene.time.delayedCall(2000, () => { 

			this.isPlayerMovable = true

		}, [], this);

	}

...

update(cursors: Phaser.Types.Input.Keyboard.CursorKeys)

    {
...
if (this.isLeftKeyDown && this.isPlayerMovable)

  {...}

}