1

I want to reset my p5.js sketch. The current way resets my gamestate, but not the deltaTime. The problem is, that I calculate my movement by a factor of the deltaTime. This means if I reset my gameState and call the noLoop function the deltaTime (which counts the time between two frames) continues counting. And as soon as I reinitialize my sketch and call the loop function, I have a big deltaTime and also a big movement of my objects. But as a restart should be, everything has to start at zero and not already in movement.

Is there any way to prevent this behavior?

Thanks and sorry if my English is trash

Jason Aller
  • 3,541
  • 28
  • 38
  • 38

1 Answers1

0

Why is it that you call a noLoop while resetting the gameState? You should just be able to reset the gameState at the end of your draw or loop function and if that is not possible then the deltaTime variable in p5js is mutable so before you start the loop again you should just be able to do deltaTime = 0

herohamp
  • 615
  • 4
  • 13