How do I check a button pressed along with a OnTimer?

0 favourites
  • 7 posts
From the Asset Store
J-BoB Game Button Sound Pack comes with 300 high-quality sound effects
  • Hi!

    I want to make a Rhythm game. I found in the forum a nice way to have the beat of the music, which is the basis of everything that follows.

    Basically what I do is that I have a variable "bpm" which corresponds to the bpm of my music, and I start a timer for 1/(bpm/60), bpm/60 = beat per second, and 1/bps = seconds per beat. It works pretty great.

    Then what I do is I add 1 to a variable "nbBeat" every time we are on timer (= every beat). With this I can keep track of the beats and their number. With this I can start special events at some point of the music, animate sprites accordingly, etc.

    I can also do some modulo to get the even numbers and do something with it. Anyway, you get the idea.

    Now what I want to do, is to check if a player tap the button at the corresponding beat (for now, every beat). And by extending this, I want to check if the player missed a bit or is pressing the button off beat.

    But I saw that you can't check for a button pressed and a OnTimer in the same event. What I did is that when we are OnTimer, I change a sprite to an animation. And then in another event I have "when this animation is playing AND player is pressing <key>", which set a boolean to true for the time of a beat. It's a bit crappy but it kinda works, not perfectly tho. Also, this solution doesn't work with the situation where the player miss a beat.

    So, here is my question:

    How can I check if the player is pressing a button on timer? How can I check if he missed a beat, or if he is off beat?

    Thanks a lot for your help.

    You can see the basic rhythm stuff with the timer here:

    Subscribe to Construct videos now

    And here are some crappy events of what I just explained;

  • I don't think it's humanly possible to press the button at exactly the same milli-second off the "on timer".

    It might be better to check the time passed since the last timer to see how close to the beat the player has pushed.

  • Like some time of range before and after the on timer in which the player has to press the button?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yes.. It can be a very short time..

    You could even have -perfect/good/bad/missed/too soon/too late- depending on the time the player pushes.

  • After doing some research, I found that what could be useful is the CurrentTime() expression from the Timer, but it only gives you the current time after each beat, so I don't know how you could use it to detect a range before a beat, or to make a level design that doesn't need the player to press for every beat.

    Maybe I can do it with the time (= Duration()), and make each range manually, but it wouldn't be very smart I guess?

    Any ideas?

    Thanks for your help.

  • Store system.time in a variable on timer

    subtract it from system.time on key press

    this should give you the amount of time passed since the last on timer event.

    You know the time between beats, so it also gives you the time before the next beat.

  • I'll look into it, thanks

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