Button Response Time - Rhythm Minigame

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
CharlieFuu69
Regular
Posts: 30
Joined: Mon Nov 11, 2019 10:32 pm
Projects: Current projects using Ren'Py : "Tears: The First Love!" (Visual Novel at 90%) , "ElectroBasics Electronic Quiz!" (Educative game at 45%).
Location: Chile
Contact:

Button Response Time - Rhythm Minigame

#1 Post by CharlieFuu69 » Thu Oct 20, 2022 6:53 pm

Hello everyone.
More than asking about solving a problem, I wanted to leave on the table a question that appears together with an idea that I had a long time ago.

In my game I have thought about integrating a system that allows you to touch keys to the rhythm of the music, that is, to integrate the dynamics of a rhythm game, especially thinking about Android devices.
The logic of the rhythm game is almost fully developed, except for a fairly specific issue that involves the screens. We all know that the basis of a rhythm game is the precision of reaction, both by the player and by the game itself, and that is exactly what I wanted to get to.

I have noticed that, basically, textbuttons, imagebuttons and buttons consider 3 important events: the idle event, the hover event and the activate event (this last one, of high importance for what I want to do).
Remember that above I said that precision is the basis of a rhythm game? I noticed that in the "idle-hover-activate" sequence of events it takes a fraction of the time to execute the button action.
The sequence would be something like this:

Code: Select all

[Touch button]
               |
               |---> idle event (by default)
  Delay: X ms  |---> hover event
               |---> activate event (hit note)
               |
[Release finger]
This situation can ruin the gaming experience on mobile phones, because of course, on PC you can use the keyboard to play the notes, but the behavior on touch devices such as mobile phones is different since apparently Ren'Py listens to the entire sequence to just execute the action (in this case, count the note pressed).

Is there a way to ignore "idle-hover" events and only consider the "activate" event to avoid the delay, in Ren'Py buttons?

That would be the only thing that makes it difficult for me to implement a rhythm action minigame. I appreciate the time you took to read this =D

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Button Response Time - Rhythm Minigame

#2 Post by Alex » Fri Oct 21, 2022 1:00 pm

How's the actual code of your game looks like?
Screen buttons are slow, so this might be better to track the mouse position when clicked and check if it was in 'right' place.

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Button Response Time - Rhythm Minigame

#3 Post by _ticlock_ » Fri Oct 21, 2022 3:54 pm

CharlieFuu69 wrote:
Thu Oct 20, 2022 6:53 pm
I would try using CDD for that. This way you can only process click(touch) without processing other "events". If you don't want to process a long-press touch you can just use pygame.MOUSEBUTTONDOWN, which is a better estimate of player's reaction.

User avatar
CharlieFuu69
Regular
Posts: 30
Joined: Mon Nov 11, 2019 10:32 pm
Projects: Current projects using Ren'Py : "Tears: The First Love!" (Visual Novel at 90%) , "ElectroBasics Electronic Quiz!" (Educative game at 45%).
Location: Chile
Contact:

Re: Button Response Time - Rhythm Minigame

#4 Post by CharlieFuu69 » Sat Oct 22, 2022 4:33 am

How's the actual code of your game looks like?
At the moment I have only created the main base of the rhythm game, that is, the reading of a beatmap (based on a file with the timestamps corresponding to each note), the playback of the audio and a synchronization stopwatch based on time.time()
I tested the button behavior separately from the rhythm game system, as I was suspicious beforehand (I was planning to implement the visual part when the reaction time was acceptable).
If you don't want to process a long-press touch you can just use pygame.MOUSEBUTTONDOWN
Part of me considered that same mechanism, but to be honest, I haven't tried it on Android.
For this to work, do I need to import pygame_sdl2 before all the code, or does Ren'Py already import it every time the game starts?

In conclusion, your suggestions seem to be quite appropriate to solve this problem.
Thanks for replying guys!

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Button Response Time - Rhythm Minigame

#5 Post by _ticlock_ » Sat Oct 22, 2022 11:18 pm

CharlieFuu69 wrote:
Sat Oct 22, 2022 4:33 am
Part of me considered that same mechanism, but to be honest, I haven't tried it on Android.
For this to work, do I need to import pygame_sdl2 before all the code, or does Ren'Py already import it every time the game starts?
Ren'Py engine uses pygame, but I believe you still need to import it. Just looked in the Tutorial to be sure. It uses:

Code: Select all

import pygame
I am not sure if I used it on Android. But you can check it with pong game inside the Ren'Py Tutorial.

User avatar
CharlieFuu69
Regular
Posts: 30
Joined: Mon Nov 11, 2019 10:32 pm
Projects: Current projects using Ren'Py : "Tears: The First Love!" (Visual Novel at 90%) , "ElectroBasics Electronic Quiz!" (Educative game at 45%).
Location: Chile
Contact:

Re: Button Response Time - Rhythm Minigame

#6 Post by CharlieFuu69 » Mon Oct 24, 2022 6:25 pm

Ok, I think I'm already having some positive results, except for one detail in Android (especially for playing simultaneous notes).

I understand that you have to capture the location of the pointers, and of course, on PC it can be obtained through renpy.get_mouse_pos(), which returns a tuple with (x, y), but in the case of Multitouch activities (simultaneous notes) this has no effect as it only returns a single position.

Is there any alternative to capture 2 pointers (fingers on the screen) at the same time?

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Button Response Time - Rhythm Minigame

#7 Post by _ticlock_ » Tue Oct 25, 2022 11:03 am

CharlieFuu69 wrote:
Mon Oct 24, 2022 6:25 pm
Ok, I think I'm already having some positive results, except for one detail in Android (especially for playing simultaneous notes).

I understand that you have to capture the location of the pointers, and of course, on PC it can be obtained through renpy.get_mouse_pos(), which returns a tuple with (x, y), but in the case of Multitouch activities (simultaneous notes) this has no effect as it only returns a single position.

Is there any alternative to capture 2 pointers (fingers on the screen) at the same time?
Are you trying CDD or another approach? For CDD, you don't really need renpy.get_mouse_pos(), you can always get the mouse position inside the event method:

Code: Select all

    class Rhythm(renpy.Displayable):
        ...
        def event(self, ev, x, y, st):
            if ev.type == pygame.MOUSEBUTTONDOWN and ev.button == 1:
                # x, y is mouse position on touch
                ...
However, I am not sure if Ren'py supports multitouch events.

User avatar
CharlieFuu69
Regular
Posts: 30
Joined: Mon Nov 11, 2019 10:32 pm
Projects: Current projects using Ren'Py : "Tears: The First Love!" (Visual Novel at 90%) , "ElectroBasics Electronic Quiz!" (Educative game at 45%).
Location: Chile
Contact:

Re: Button Response Time - Rhythm Minigame

#8 Post by CharlieFuu69 » Wed Oct 26, 2022 1:11 pm

Are you trying CDD or another approach?
I had implemented it in Python, but without the CDD approach (as the documentation suggests).
With the changes I've made in the code, I've been able to adapt it enough as a CDD, but when it comes to Multitouch it's complicated...

And speaking of Multitouch...
However, I am not sure if Ren'py supports multitouch events.
I also have no idea if it is capable of recognizing multiple touches on the screen. Recognizing buttons on a keyboard is not a problem, but getting multiple taps seems to be the enemy at the moment haha

Post Reply

Who is online

Users browsing this forum: Google [Bot]