P5.js: Suggestion to `millis()`

Created on 27 Aug 2019  路  7Comments  路  Source: processing/p5.js

Nature of issue?

  • [x] Existing feature enhancement

Most appropriate sub-area of p5.js?

  • [x] Core/Environment/Rendering
  • [x] Events
  • [x] IO

Which platform were you using when you encountered this?

  • [x] Mobile/Tablet (touch devices)
  • [x] Desktop/Laptop

Details about the bug:

  • p5.js version: p5.js v0.7.3 January 20, 2019
  • Web browser and version: Any
  • Operating System: Any
  • Steps to reproduce this:

Feature enhancement details:

Hi, I am using p5js to create a game which uses the time to calculate the level of the game.
By using millis() function, I can get the time which is how long my canvas exists. The problem comes when I am using noLoop() to pause the game but millis() does not stop counting. I wonder if someone could add any kind of property to millis() function e.g millis(ACTIVE_CANVAS) so I can get what I need.

New feature details:

I would love to see a new method that returns the time I described above. Something like canvas_millis()

core enhancement

Most helpful comment

This might be a case where the user is expected to make their own way of tracking this. The problem becomes the difficulty with mentally converting frames to milliseconds. Like I am not sure what I would expect canvas_millis() to return on a canvas that has existed for 1000ms but has had a framerate of 10.

This might be a good opportunity to use deltaTime. You can do something like this:

function draw() {
  if(paused === false) {
    activeCanvasMS += deltaTime;
  }
}

All 7 comments

Welcome! 馃憢 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already.

This might be a case where the user is expected to make their own way of tracking this. The problem becomes the difficulty with mentally converting frames to milliseconds. Like I am not sure what I would expect canvas_millis() to return on a canvas that has existed for 1000ms but has had a framerate of 10.

This might be a good opportunity to use deltaTime. You can do something like this:

function draw() {
  if(paused === false) {
    activeCanvasMS += deltaTime;
  }
}

I actually used deltaTime for my project. When I want to get the current active time of canvas, I just call millis() - activeCanvasMs. What if that was a whole new feature, so nobody has to implement it by hand

The implementation on the user side is relatively simple and straightforward so I don't think it is something essential to include in the library. For me, the aim is not to include all possible features but provide enough simple and basic tool sets that the users can build things up as they need to.

@limzykenneth well, when using deltaTime, I am getting errors in Safari and canvas is not rendering. So yeah, if I am not wrong, that is a problem and needs an alternative fix.

Hi @PixsaOJ I made an example showing your requested use of deltaTime. This example works on the most recent Firefox, Chrome, and I tested on two versions of Safari (12.1.1 and 12.1.2). If you are able to recreate a bug please open a different issue with a simple code example and hardware/browser details. Thank you!

In terms of the requested features, as @limzykenneth stated nicely, the goal isn't to provide features for every possible use, and since this is relatively straightforward to make with the features provided it doesn't make sense for us to add additional features at this time. I am closing this issue for the time being for organizational purposes.

@stalgiag Thank you. I will test it on different browsers.

Was this page helpful?
0 / 5 - 0 ratings