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

Get help using Construct 2

Post » Tue Apr 14, 2015 12:04 pm

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: https://www.youtube.com/watch?v=IvFxuIhE9V8
And here are some crappy events of what I just explained;
Image
B
6
S
2
G
1
Posts: 38
Reputation: 603

Post » Tue Apr 14, 2015 1:09 pm

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.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Apr 14, 2015 2:41 pm

Like some time of range before and after the on timer in which the player has to press the button?
B
6
S
2
G
1
Posts: 38
Reputation: 603

Post » Tue Apr 14, 2015 2:47 pm

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.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Apr 15, 2015 9:26 am

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.
B
6
S
2
G
1
Posts: 38
Reputation: 603

Post » Wed Apr 15, 2015 10:03 am

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 told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Apr 15, 2015 12:20 pm

I'll look into it, thanks
B
6
S
2
G
1
Posts: 38
Reputation: 603


Return to How do I....?

Who is online

Users browsing this forum: MuchaDev, tetuan, tikuna and 5 guests