Skip to content

[p5.js 2.0 Bug Report]: millis() now includes time loading assets #8001

@davepagurek

Description

@davepagurek

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

2.0.3

Web browser and version

all

Operating system

macOS

Steps to reproduce this

In both 1.x and 2.x, we record the system time right before setup runs, and then future millis() calls subtract that from the system time. However, in 1.x, this happened after preload, but in 2.x, this is before preloads, since they now occur in setup.

I think this is a problem because millis and frameCount, to me, should be equivalent except for one difference. Both are used to control animations, but frameCount always draws every frame of your animation, running slower than your target frame rate if need be, while millis will skip frames to make sure your animation's timing always matches real time. In 2.x, a new difference has been added, which is that they start at different points in the sketch's lifecycle. In 2.0, you would have to manually record the time at the end of setup and subtract it everywhere you use millis in draw in order to achieve the same behaviour as 1.x. If you make no change, animations that worked in 1.x look like their beginnings are cut off in 2.x.

We could possibly:

  • only set up millis after setup, so times don't work within it
  • reset millis after setup, so timing still works in setup but starts from 0 again when your draw loop begins
  • something else?

I personally lean towards that second option, to allow you to possibly roll your own loading animation in setup.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions