How do I accurately change the width of a progress bar sprite based on the number of seconds?

0 favourites
  • 5 posts
From the Asset Store
Progress\Loading Bar. Now Load you game like a Professional.
  • Need help please!

    I'm creating a button that, when held for 3 seconds, restarts the layout. However, I'm having trouble getting the progress bar sprite (total width: 208) to actually sync with the number of seconds pressed.

    I have a couple of questions:

    1) Why are the timers messed up? If every 1 second I add 1, it should be equal to if every 0.001 seconds I add 1/1000 since 1 second = 1000 milliseconds yet when I did that to try and figure out the problem I got a different result? I got the "correct" result when I did every 0.001 seconds I add 1/60

    2) Is there an easier way to do this where I can use Tweening instead and forego the whole timer part, the whole reason I'm going with every 0.001 second is so the progress bar moves smoothly and not in chunks.

    Screen recording of the debug preview: streamable.com/aj2tz8

    Project file: dropbox.com/s/odxh7b09jnz2x7d/HoldButtonToRestart.c3p

  • May be I understand this all wrong, but would it not be easier to use pixel per tick instead?

    + System: ProgressBar.Width ≤ 208
    + Mouse: Left button is down
    -> ProgressBar: Set width to Self.Width+(208÷3)×dt
    
    + Mouse: On Left button released
    -> ProgressBar: Set width to 0
    

    With 208 the width and 3 the 3 seconds and if you have 60 FPS it would add (208/3) * (1/60) = 1.1556 pixel per tick to the width.

  • May be I understand this all wrong, but would it not be easier to use pixel per tick instead?

    > + System: ProgressBar.Width ≤ 208
    + Mouse: Left button is down
    -> ProgressBar: Set width to Self.Width+(208÷3)×dt
    
    + Mouse: On Left button released
    -> ProgressBar: Set width to 0
    

    With 208 the width and 3 the 3 seconds and if you have 60 FPS it would add (208/3) * (1/60) = 1.1556 pixel per tick to the width.

    Hey! Thanks for answering! I think that would fix this particular problem but I wanted it to be based on actual time pressed and not ticks or fps (so its exactly the same no matter the device)

    Someone told me that the "Every X Seconds" isn't accurate and I should instead use a timer but Im struggling to understand how to use one

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You can use date object

    https://drive.google.com/file/d/1r__11nFBRCVxXzGvVcZ5KO4L_Q7ZP1EX/view?usp=sharing

    Thank a lot for taking the time to help! I eventually managed to get the timer to work, but this definitely works too! I'm pretty new to all this so, considering both got me the desired result, which one is more efficient and when/why would you use one over the other?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)