We need to specify how long the animation should take, and measure how long it has taken so far.
- Create two new number variables,
animationTimeto something long for now, like
3, and let
- We can figure out how much time has passed using a handy property of the game called
frameDeltaTime. It measures, in seconds, how long each tick takes.
- Just after the line where you increment the chest’s Y position, increment
this.elapsedTime += this.game.frameDeltaTime
- Add another line to log the value of
elapsedTimeto the console, so that we can see how long the animation currently takes.